Skip to content

Commit fdc58a6

Browse files
test: Transform snapshots into rtl tests (#674)
1 parent 90aa652 commit fdc58a6

File tree

5 files changed

+22
-114
lines changed

5 files changed

+22
-114
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"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",
2020
"test": "TZ=GMT fedx-scripts jest --coverage --passWithNoTests",
2121
"quality": "npm run lint-fix && npm run test",
22-
"watch-tests": "jest --watch",
23-
"snapshot": "fedx-scripts jest --updateSnapshot"
22+
"watch-tests": "jest --watch"
2423
},
2524
"author": "edX",
2625
"license": "AGPL-3.0",

src/__snapshots__/index.test.jsx.snap

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/containers/CourseCard/components/CourseCardDetails/__snapshots__/index.test.jsx.snap

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/containers/CourseCard/components/CourseCardDetails/index.test.jsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React from 'react';
2-
import { render } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
32

43
import CourseCardDetails from '.';
54

@@ -48,23 +47,36 @@ describe('CourseCard Details component', () => {
4847
return separatorsCount;
4948
};
5049

51-
test('has change session button on entitlement course', () => {
50+
it('has change session button on entitlement course', () => {
5251
const wrapper = createWrapper();
53-
expect(wrapper.container).toMatchSnapshot();
52+
const sessionButton = screen.getByRole('button', { name: defaultHooks.changeOrLeaveSessionMessage });
53+
expect(sessionButton).toBeInTheDocument();
54+
55+
const accessMessage = screen.getByText((text) => text.includes(defaultHooks.accessMessage));
56+
expect(accessMessage).toBeInTheDocument();
5457
// it has 3 separator, 4 column
5558
expect(fetchSeparators(wrapper)).toBe(3);
5659
});
5760

58-
test('has change session button on entitlement course but no access message', () => {
61+
it('has change session button on entitlement course but no access message', () => {
5962
const wrapper = createWrapper({ accessMessage: null });
60-
expect(wrapper.container).toMatchSnapshot();
63+
const sessionButton = screen.getByRole('button', { name: defaultHooks.changeOrLeaveSessionMessage });
64+
expect(sessionButton).toBeInTheDocument();
65+
66+
const accessMessage = screen.queryByText((text) => text.includes(defaultHooks.accessMessage));
67+
expect(accessMessage).toBeNull();
68+
6169
// it has 2 separator, 3 column
6270
expect(fetchSeparators(wrapper)).toBe(2);
6371
});
6472

65-
test('does not have change session button on regular course', () => {
73+
it('does not have change session button on regular course', () => {
6674
const wrapper = createWrapper({ isEntitlement: false });
67-
expect(wrapper.container).toMatchSnapshot();
75+
const sessionButton = screen.queryByRole('button', { name: defaultHooks.changeOrLeaveSessionMessage });
76+
expect(sessionButton).toBeNull();
77+
78+
const accessMessage = screen.getByText((text) => text.includes(defaultHooks.accessMessage));
79+
expect(accessMessage).toBeInTheDocument();
6880
// it has 2 separator, 3 column
6981
expect(fetchSeparators(wrapper)).toBe(2);
7082
});

src/index.test.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,12 @@ describe('app registry', () => {
5555
const callArgs = subscribe.mock.calls[0];
5656
expect(callArgs[0]).toEqual(APP_READY);
5757
callArgs[1]();
58-
const [rendered] = mockRender.mock.calls[0];
59-
expect(rendered).toMatchSnapshot();
6058
});
61-
test('subscribe: APP_INIT_ERROR. snapshot: displays an ErrorPage to root element', () => {
59+
test('subscribe: APP_INIT_ERROR.', () => {
6260
const callArgs = subscribe.mock.calls[1];
6361
expect(callArgs[0]).toEqual(APP_INIT_ERROR);
6462
const error = { message: 'test-error-message' };
6563
callArgs[1](error);
66-
const [rendered] = mockRender.mock.calls[0];
67-
expect(rendered).toMatchSnapshot();
6864
});
6965
test('initialize is called with requireAuthenticatedUser', () => {
7066
expect(initialize).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)