Skip to content

Commit 2acf7fb

Browse files
test: Deprecate react-unit-test-utils 10/15 (#658)
1 parent cae7b1b commit 2acf7fb

File tree

10 files changed

+164
-576
lines changed

10 files changed

+164
-576
lines changed

src/containers/SelectSessionModal/__snapshots__/index.test.jsx.snap

Lines changed: 0 additions & 176 deletions
This file was deleted.
Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import React from 'react';
2-
import { shallow } from '@edx/react-unit-test-utils';
3-
1+
import { render, screen } from '@testing-library/react';
2+
import { formatMessage } from 'testUtils';
3+
import { IntlProvider } from '@edx/frontend-platform/i18n';
44
import hooks from './hooks';
55
import SelectSessionModal from '.';
6+
import messages from './messages';
67

78
jest.mock('./hooks', () => ({
89
__esModule: true,
910
default: jest.fn(),
1011
}));
1112

13+
jest.unmock('@edx/frontend-platform/i18n');
14+
jest.unmock('@openedx/paragon');
15+
jest.unmock('react');
16+
1217
const hookReturn = {
1318
availableSessions: [],
1419
showModal: true,
@@ -25,29 +30,41 @@ const availableSessions = [
2530
];
2631

2732
describe('SelectSessionModal', () => {
28-
describe('snapshot', () => {
29-
test('empty modal with leave option ', () => {
33+
describe('renders', () => {
34+
it('empty modal with leave option ', () => {
3035
hooks.mockReturnValueOnce({
3136
...hookReturn,
3237
});
33-
expect(shallow(<SelectSessionModal />).snapshot).toMatchSnapshot();
38+
render(<IntlProvider locale="en"><SelectSessionModal /></IntlProvider>);
39+
const sessionOption = screen.queryByDisplayValue(availableSessions[0].courseId);
40+
expect(sessionOption).toBeNull();
41+
const leaveOption = screen.getByRole('radio', { name: formatMessage(messages.leaveSessionOption) });
42+
expect(leaveOption).toBeInTheDocument();
3443
});
3544

36-
test('modal with leave option ', () => {
45+
it('modal with leave option ', () => {
3746
hooks.mockReturnValueOnce({
3847
...hookReturn,
39-
availableSessions: [...availableSessions],
48+
availableSessions,
4049
});
41-
expect(shallow(<SelectSessionModal />).snapshot).toMatchSnapshot();
50+
render(<IntlProvider locale="en"><SelectSessionModal /></IntlProvider>);
51+
const sessionOption = screen.getByDisplayValue(availableSessions[0].courseId);
52+
expect(sessionOption).toBeInTheDocument();
53+
const leaveOption = screen.getByRole('radio', { name: formatMessage(messages.leaveSessionOption) });
54+
expect(leaveOption).toBeInTheDocument();
4255
});
4356

44-
test('modal without leave option ', () => {
57+
it('modal without leave option ', () => {
4558
hooks.mockReturnValueOnce({
4659
...hookReturn,
4760
availableSessions,
4861
showLeaveOption: false,
4962
});
50-
expect(shallow(<SelectSessionModal />).snapshot).toMatchSnapshot();
63+
render(<IntlProvider locale="en"><SelectSessionModal /></IntlProvider>);
64+
const sessionOption = screen.getByDisplayValue(availableSessions[0].courseId);
65+
expect(sessionOption).toBeInTheDocument();
66+
const leaveOption = screen.queryByRole('radio', { name: formatMessage(messages.leaveSessionOption) });
67+
expect(leaveOption).toBeNull();
5168
});
5269
});
5370
});

src/containers/UnenrollConfirmModal/__snapshots__/index.test.jsx.snap

Lines changed: 0 additions & 101 deletions
This file was deleted.
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
import React from 'react';
2-
import { shallow } from '@edx/react-unit-test-utils';
1+
import { render, screen } from '@testing-library/react';
2+
import { formatMessage } from 'testUtils';
3+
import { IntlProvider } from '@edx/frontend-platform/i18n';
34

45
import { ConfirmPane } from './ConfirmPane';
6+
import messages from './messages';
7+
8+
jest.unmock('@edx/frontend-platform/i18n');
9+
jest.unmock('@openedx/paragon');
10+
jest.unmock('react');
11+
12+
const props = {
13+
handleClose: jest.fn().mockName('props.handleClose'),
14+
handleConfirm: jest.fn().mockName('props.handleConfirm'),
15+
};
516

617
describe('UnenrollConfirmModal ConfirmPane', () => {
7-
test('snapshot', () => {
8-
const props = {
9-
handleClose: jest.fn().mockName('props.handleClose'),
10-
handleConfirm: jest.fn().mockName('props.handleConfirm'),
11-
};
12-
expect(shallow(<ConfirmPane {...props} />).snapshot).toMatchSnapshot();
18+
beforeEach(() => {
19+
jest.clearAllMocks();
20+
render(<IntlProvider locale="en"><ConfirmPane {...props} /></IntlProvider>);
21+
});
22+
it('renders title', () => {
23+
const header = screen.getByText(formatMessage(messages.confirmHeader));
24+
expect(header).toBeInTheDocument();
25+
});
26+
it('renders cancel button', () => {
27+
const cancelButton = screen.getByRole('button', { name: formatMessage(messages.confirmCancel) });
28+
expect(cancelButton).toBeInTheDocument();
29+
});
30+
it('renders unenroll button', () => {
31+
const unenrollButton = screen.getByRole('button', { name: formatMessage(messages.confirmUnenroll) });
32+
expect(unenrollButton).toBeInTheDocument();
1333
});
1434
});

0 commit comments

Comments
 (0)