test: Transform snapshots into rtl tests (#674)
This commit is contained in:
@@ -19,8 +19,7 @@
|
||||
"dev": "PUBLIC_PATH=/learner-dashboard/ MFE_CONFIG_API_URL='http://localhost:8000/api/mfe_config/v1' fedx-scripts webpack-dev-server --progress --host apps.local.openedx.io",
|
||||
"test": "TZ=GMT fedx-scripts jest --coverage --passWithNoTests",
|
||||
"quality": "npm run lint-fix && npm run test",
|
||||
"watch-tests": "jest --watch",
|
||||
"snapshot": "fedx-scripts jest --updateSnapshot"
|
||||
"watch-tests": "jest --watch"
|
||||
},
|
||||
"author": "edX",
|
||||
"license": "AGPL-3.0",
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`app registry subscribe: APP_INIT_ERROR. snapshot: displays an ErrorPage to root element 1`] = `
|
||||
<UNDEFINED>
|
||||
<ErrorPage
|
||||
message="test-error-message"
|
||||
/>
|
||||
</UNDEFINED>
|
||||
`;
|
||||
|
||||
exports[`app registry subscribe: APP_READY. links App to root element 1`] = `
|
||||
<UNDEFINED>
|
||||
<AppProvider
|
||||
store={
|
||||
{
|
||||
"redux": "store",
|
||||
}
|
||||
}
|
||||
>
|
||||
<NoticesWrapper>
|
||||
<Routes>
|
||||
<Route
|
||||
element={
|
||||
<PageWrap>
|
||||
<App />
|
||||
</PageWrap>
|
||||
}
|
||||
path="/"
|
||||
/>
|
||||
<Route
|
||||
element={
|
||||
<Navigate
|
||||
replace={true}
|
||||
to="/"
|
||||
/>
|
||||
}
|
||||
path="*"
|
||||
/>
|
||||
</Routes>
|
||||
</NoticesWrapper>
|
||||
</AppProvider>
|
||||
</UNDEFINED>
|
||||
`;
|
||||
@@ -1,56 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`CourseCard Details component does not have change session button on regular course 1`] = `
|
||||
<div>
|
||||
<span
|
||||
class="small"
|
||||
data-testid="CourseCardDetails"
|
||||
>
|
||||
provider-name
|
||||
•
|
||||
test-course-number
|
||||
• access-message
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`CourseCard Details component has change session button on entitlement course 1`] = `
|
||||
<div>
|
||||
<span
|
||||
class="small"
|
||||
data-testid="CourseCardDetails"
|
||||
>
|
||||
provider-name
|
||||
•
|
||||
test-course-number
|
||||
• access-message
|
||||
•
|
||||
<button
|
||||
class="m-0 p-0"
|
||||
variant="link"
|
||||
>
|
||||
change-or-leave-session-message
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`CourseCard Details component has change session button on entitlement course but no access message 1`] = `
|
||||
<div>
|
||||
<span
|
||||
class="small"
|
||||
data-testid="CourseCardDetails"
|
||||
>
|
||||
provider-name
|
||||
•
|
||||
test-course-number
|
||||
•
|
||||
<button
|
||||
class="m-0 p-0"
|
||||
variant="link"
|
||||
>
|
||||
change-or-leave-session-message
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
@@ -1,5 +1,4 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
import CourseCardDetails from '.';
|
||||
|
||||
@@ -48,23 +47,36 @@ describe('CourseCard Details component', () => {
|
||||
return separatorsCount;
|
||||
};
|
||||
|
||||
test('has change session button on entitlement course', () => {
|
||||
it('has change session button on entitlement course', () => {
|
||||
const wrapper = createWrapper();
|
||||
expect(wrapper.container).toMatchSnapshot();
|
||||
const sessionButton = screen.getByRole('button', { name: defaultHooks.changeOrLeaveSessionMessage });
|
||||
expect(sessionButton).toBeInTheDocument();
|
||||
|
||||
const accessMessage = screen.getByText((text) => text.includes(defaultHooks.accessMessage));
|
||||
expect(accessMessage).toBeInTheDocument();
|
||||
// it has 3 separator, 4 column
|
||||
expect(fetchSeparators(wrapper)).toBe(3);
|
||||
});
|
||||
|
||||
test('has change session button on entitlement course but no access message', () => {
|
||||
it('has change session button on entitlement course but no access message', () => {
|
||||
const wrapper = createWrapper({ accessMessage: null });
|
||||
expect(wrapper.container).toMatchSnapshot();
|
||||
const sessionButton = screen.getByRole('button', { name: defaultHooks.changeOrLeaveSessionMessage });
|
||||
expect(sessionButton).toBeInTheDocument();
|
||||
|
||||
const accessMessage = screen.queryByText((text) => text.includes(defaultHooks.accessMessage));
|
||||
expect(accessMessage).toBeNull();
|
||||
|
||||
// it has 2 separator, 3 column
|
||||
expect(fetchSeparators(wrapper)).toBe(2);
|
||||
});
|
||||
|
||||
test('does not have change session button on regular course', () => {
|
||||
it('does not have change session button on regular course', () => {
|
||||
const wrapper = createWrapper({ isEntitlement: false });
|
||||
expect(wrapper.container).toMatchSnapshot();
|
||||
const sessionButton = screen.queryByRole('button', { name: defaultHooks.changeOrLeaveSessionMessage });
|
||||
expect(sessionButton).toBeNull();
|
||||
|
||||
const accessMessage = screen.getByText((text) => text.includes(defaultHooks.accessMessage));
|
||||
expect(accessMessage).toBeInTheDocument();
|
||||
// it has 2 separator, 3 column
|
||||
expect(fetchSeparators(wrapper)).toBe(2);
|
||||
});
|
||||
|
||||
@@ -55,16 +55,12 @@ describe('app registry', () => {
|
||||
const callArgs = subscribe.mock.calls[0];
|
||||
expect(callArgs[0]).toEqual(APP_READY);
|
||||
callArgs[1]();
|
||||
const [rendered] = mockRender.mock.calls[0];
|
||||
expect(rendered).toMatchSnapshot();
|
||||
});
|
||||
test('subscribe: APP_INIT_ERROR. snapshot: displays an ErrorPage to root element', () => {
|
||||
test('subscribe: APP_INIT_ERROR.', () => {
|
||||
const callArgs = subscribe.mock.calls[1];
|
||||
expect(callArgs[0]).toEqual(APP_INIT_ERROR);
|
||||
const error = { message: 'test-error-message' };
|
||||
callArgs[1](error);
|
||||
const [rendered] = mockRender.mock.calls[0];
|
||||
expect(rendered).toMatchSnapshot();
|
||||
});
|
||||
test('initialize is called with requireAuthenticatedUser', () => {
|
||||
expect(initialize).toHaveBeenCalledTimes(1);
|
||||
|
||||
Reference in New Issue
Block a user