Skip to content

Commit 93d888d

Browse files
test: replacing snapshot tests with rtl tests part 13
1 parent 75ea750 commit 93d888d

File tree

14 files changed

+173
-824
lines changed

14 files changed

+173
-824
lines changed

src/editors/containers/VideoEditor/components/VideoSettingsModal/components/HandoutWidget/__snapshots__/index.test.jsx.snap

Lines changed: 0 additions & 165 deletions
This file was deleted.
Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
import 'CourseAuthoring/editors/setupEditorTest';
21
import React from 'react';
3-
import { shallow } from '@edx/react-unit-test-utils';
4-
5-
import { formatMessage } from '../../../../../../testUtils';
6-
import { actions, selectors } from '../../../../../../data/redux';
2+
import { render, screen, initializeMocks } from '@src/testUtils';
3+
import { formatMessage } from '@src/editors/testUtils';
4+
import { actions, selectors } from '@src/editors/data/redux';
75
import { HandoutWidgetInternal as HandoutWidget, mapStateToProps, mapDispatchToProps } from '.';
86

9-
jest.mock('react', () => ({
10-
...jest.requireActual('react'),
11-
useContext: jest.fn(() => ({ handout: ['error.handout', jest.fn().mockName('error.setHandout')] })),
12-
}));
13-
14-
jest.mock('../../../../../../data/redux', () => ({
7+
jest.mock('@src/editors/data/redux', () => ({
158
actions: {
169
video: {
1710
updateField: jest.fn().mockName('actions.video.updateField'),
@@ -33,48 +26,57 @@ jest.mock('../../../../../../data/redux', () => ({
3326

3427
describe('HandoutWidget', () => {
3528
const props = {
36-
subtitle: 'SuBTItle',
37-
title: 'tiTLE',
3829
intl: { formatMessage },
3930
isLibrary: false,
4031
handout: '',
32+
isUploadError: false,
4133
getHandoutDownloadUrl: jest.fn().mockName('args.getHandoutDownloadUrl'),
4234
updateField: jest.fn().mockName('args.updateField'),
4335
};
4436

45-
describe('snapshots', () => {
46-
test('snapshots: renders as expected with default props', () => {
47-
expect(
48-
shallow(<HandoutWidget {...props} />).snapshot,
49-
).toMatchSnapshot();
37+
describe('renders', () => {
38+
beforeEach(() => {
39+
initializeMocks();
5040
});
51-
test('snapshots: renders as expected with isLibrary true', () => {
52-
expect(
53-
shallow(<HandoutWidget {...props} isLibrary />).snapshot,
54-
).toMatchSnapshot();
41+
test('renders as expected with default props', () => {
42+
render(<HandoutWidget {...props} />);
43+
expect(screen.getByText('Handout')).toBeInTheDocument();
44+
expect(screen.getByRole('button', { name: 'Upload Handout' })).toBeInTheDocument();
45+
expect(screen.getByRole('button', { name: 'Handout' })).toBeInTheDocument();
46+
expect(screen.getByRole('button', { name: 'Collapse' })).toBeInTheDocument();
5547
});
56-
test('snapshots: renders as expected with handout', () => {
57-
expect(
58-
shallow(<HandoutWidget {...props} handout="sOMeUrl " />).snapshot,
59-
).toMatchSnapshot();
48+
test('renders as expected with isLibrary true', () => {
49+
const { container } = render(<HandoutWidget {...props} isLibrary />);
50+
const reduxWrapper = container.firstChild;
51+
expect(reduxWrapper?.textContent).toBe('');
52+
expect(screen.queryByText('Handout')).not.toBeInTheDocument();
53+
});
54+
test('renders as expected with handout', () => {
55+
const handoutUrl = 'sOMeUrl ';
56+
render(<HandoutWidget {...props} handout={handoutUrl} />);
57+
expect(screen.getByText('Handout')).toBeInTheDocument();
58+
expect(screen.getByText(handoutUrl.trim())).toBeInTheDocument();
6059
});
6160
});
6261
describe('mapStateToProps', () => {
6362
const testState = { A: 'pple', B: 'anana', C: 'ucumber' };
6463
test('isLibrary from app.isLibrary', () => {
6564
expect(
6665
mapStateToProps(testState).isLibrary,
66+
// @ts-ignore
6767
).toEqual(selectors.app.isLibrary(testState));
6868
});
6969
test('getHandoutDownloadUrl from video.getHandoutDownloadUrl', () => {
7070
expect(
7171
mapStateToProps(testState).getHandoutDownloadUrl,
72+
// @ts-ignore
7273
).toEqual(selectors.video.getHandoutDownloadUrl(testState));
7374
});
7475
});
7576
describe('mapDispatchToProps', () => {
7677
const dispatch = jest.fn();
7778
test('updateField from actions.video.updateField', () => {
79+
// @ts-ignore
7880
expect(mapDispatchToProps.updateField).toEqual(dispatch(actions.video.updateField));
7981
});
8082
});

src/editors/sharedComponents/CodeEditor/__snapshots__/index.test.jsx.snap

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

src/editors/sharedComponents/CodeEditor/index.jsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@ const CodeEditor = ({
2727

2828
return (
2929
<div>
30+
<div>Outter div</div>
3031
<div id="CodeMirror" ref={DOMref} />
3132
{showBtnEscapeHTML && lang !== 'markdown' && (
32-
<Button
33-
variant="tertiary"
34-
aria-label={intl.formatMessage(messages.escapeHTMLButtonLabel)}
35-
ref={btnRef}
36-
onClick={() => hooks.escapeHTMLSpecialChars({ ref: innerRef, hideBtn })}
37-
>
38-
<FormattedMessage {...messages.escapeHTMLButtonLabel} />
39-
</Button>
33+
<>
34+
<div>DIv inside conditional</div>
35+
<Button
36+
variant="tertiary"
37+
aria-label={intl.formatMessage(messages.escapeHTMLButtonLabel)}
38+
ref={btnRef}
39+
onClick={() => hooks.escapeHTMLSpecialChars({ ref: innerRef, hideBtn })}
40+
>
41+
<FormattedMessage {...messages.escapeHTMLButtonLabel} />
42+
</Button>
43+
</>
4044
)}
4145
</div>
4246
);

0 commit comments

Comments
 (0)