Skip to content

Commit c4f565b

Browse files
test: replacing snapshot tests with RTL tests part 15 (#2248)
1 parent e8e5a3c commit c4f565b

File tree

21 files changed

+505
-1231
lines changed

21 files changed

+505
-1231
lines changed

src/editors/containers/ProblemEditor/components/EditProblemView/ExplanationWidget/__snapshots__/index.test.jsx.snap

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

src/editors/containers/ProblemEditor/components/EditProblemView/ExplanationWidget/index.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { connect } from 'react-redux';
4-
import { injectIntl, FormattedMessage, intlShape } from '@edx/frontend-platform/i18n';
4+
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
55
import { getConfig } from '@edx/frontend-platform';
66

77
import { selectors } from '../../../../../data/redux';
@@ -16,9 +16,8 @@ const ExplanationWidget = ({
1616
images,
1717
isLibrary,
1818
blockId,
19-
// injected
20-
intl,
2119
}) => {
20+
const intl = useIntl();
2221
const { editorRef, refReady, setEditorRef } = prepareEditorRef();
2322
const initialContent = settings?.solutionExplanation || '';
2423
const newContent = replaceStaticWithAsset({
@@ -66,8 +65,6 @@ ExplanationWidget.propTypes = {
6665
images: PropTypes.shape({}).isRequired,
6766
isLibrary: PropTypes.bool.isRequired,
6867
blockId: PropTypes.string.isRequired,
69-
// injected
70-
intl: intlShape.isRequired,
7168
};
7269
export const mapStateToProps = (state) => ({
7370
settings: selectors.problem.settings(state),
@@ -78,4 +75,4 @@ export const mapStateToProps = (state) => ({
7875
});
7976

8077
export const ExplanationWidgetInternal = ExplanationWidget; // For testing only
81-
export default injectIntl(connect(mapStateToProps)(ExplanationWidget));
78+
export default connect(mapStateToProps)(ExplanationWidget);

src/editors/containers/ProblemEditor/components/EditProblemView/ExplanationWidget/index.test.jsx

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import { render, screen, initializeMocks } from '@src/testUtils';
3+
import ExplanationWidget from '.';
4+
5+
jest.mock('../../../../../data/redux', () => ({
6+
__esModule: true,
7+
default: jest.fn(),
8+
selectors: {
9+
problem: {
10+
settings: jest.fn(state => ({ question: state })),
11+
},
12+
app: {
13+
learningContextId: jest.fn(state => ({ learningContextId: state })),
14+
images: jest.fn(state => ({ images: state })),
15+
isLibrary: jest.fn(state => ({ isLibrary: state })),
16+
blockId: jest.fn(state => ({ blockId: state })),
17+
},
18+
},
19+
thunkActions: {
20+
video: {
21+
importTranscript: jest.fn(),
22+
},
23+
},
24+
}));
25+
26+
jest.mock('../../../../../sharedComponents/TinyMceWidget/hooks', () => ({
27+
...jest.requireActual('../../../../../sharedComponents/TinyMceWidget/hooks'),
28+
prepareEditorRef: jest.fn(() => ({
29+
refReady: true,
30+
setEditorRef: jest.fn().mockName('prepareEditorRef.setEditorRef'),
31+
})),
32+
}));
33+
34+
jest.mock('../../../../../sharedComponents/TinyMceWidget', () => ({
35+
__esModule: true,
36+
default: () => <div>TinyMceWidget</div>,
37+
}));
38+
39+
describe('SolutionWidget', () => {
40+
const props = {
41+
settings: { solutionExplanation: 'This is my solution' },
42+
learningContextId: 'course+org+run',
43+
images: {},
44+
isLibrary: false,
45+
blockId: 'block-v1:Org+TS100+24+type@html+block@12345',
46+
};
47+
beforeEach(() => {
48+
initializeMocks();
49+
});
50+
test('renders correct default', () => {
51+
render(<ExplanationWidget {...props} />);
52+
expect(screen.getByText('Explanation')).toBeInTheDocument();
53+
expect(screen.getByText('Provide an explanation for the correct answer')).toBeInTheDocument();
54+
expect(screen.getByText('TinyMceWidget')).toBeInTheDocument();
55+
});
56+
});

src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/GeneralFeedback/__snapshots__/index.test.jsx.snap

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

src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/GeneralFeedback/index.jsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { injectIntl, FormattedMessage, intlShape } from '@edx/frontend-platform/i18n';
2+
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
33
import { Form } from '@openedx/paragon';
44
import PropTypes from 'prop-types';
55
import SettingsOption from '../../SettingsOption';
@@ -9,9 +9,8 @@ import { generalFeedbackHooks } from './hooks';
99
export const GeneralFeedbackCard = ({
1010
generalFeedback,
1111
updateSettings,
12-
// inject
13-
intl,
1412
}) => {
13+
const intl = useIntl();
1514
const { summary, handleChange } = generalFeedbackHooks(generalFeedback, updateSettings);
1615
return (
1716
<SettingsOption
@@ -38,7 +37,6 @@ export const GeneralFeedbackCard = ({
3837
GeneralFeedbackCard.propTypes = {
3938
generalFeedback: PropTypes.string.isRequired,
4039
updateSettings: PropTypes.func.isRequired,
41-
intl: intlShape.isRequired,
4240
};
4341

44-
export default injectIntl(GeneralFeedbackCard);
42+
export default GeneralFeedbackCard;

src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/GeneralFeedback/index.test.jsx

Lines changed: 0 additions & 38 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import {
3+
render, screen, initializeMocks, fireEvent,
4+
} from '@src/testUtils';
5+
import { GeneralFeedbackCard } from './index';
6+
import * as hooks from './hooks';
7+
8+
describe('GeneralFeedbackCard', () => {
9+
const props = {
10+
generalFeedback: 'sOmE_vAlUE',
11+
updateSettings: jest.fn().mockName('args.updateSettings'),
12+
};
13+
14+
const randomizationCardHooksProps = {
15+
summary: { message: { defaultMessage: 'sUmmary' } },
16+
handleChange: jest.fn().mockName('randomizationCardHooks.handleChange'),
17+
};
18+
19+
beforeEach(() => {
20+
initializeMocks();
21+
});
22+
23+
afterEach(() => {
24+
jest.restoreAllMocks();
25+
});
26+
27+
describe('behavior', () => {
28+
it('calls generalFeedbackHooks with props when initialized', () => {
29+
jest.spyOn(hooks, 'generalFeedbackHooks').mockImplementation(() => randomizationCardHooksProps);
30+
render(<GeneralFeedbackCard {...props} />);
31+
expect(hooks.generalFeedbackHooks).toHaveBeenCalledWith(props.generalFeedback, props.updateSettings);
32+
});
33+
});
34+
35+
describe('render', () => {
36+
test('renders general feedback setting card', () => {
37+
render(<GeneralFeedbackCard {...props} />);
38+
expect(screen.getByText('General Feedback')).toBeInTheDocument();
39+
expect(screen.getByText('sOmE_vAlUE')).toBeInTheDocument();
40+
fireEvent.click(screen.getByText('General Feedback'));
41+
expect(screen.getByText('Enter General Feedback')).toBeInTheDocument();
42+
});
43+
});
44+
});

0 commit comments

Comments
 (0)