Skip to content

Commit 71fa247

Browse files
test: replacing snapshot tests with RTL tests part 11 (#2214)
1 parent 31fc045 commit 71fa247

File tree

14 files changed

+185
-465
lines changed

14 files changed

+185
-465
lines changed

src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/components/Feedback/FeedbackBox.test.jsx

Lines changed: 0 additions & 31 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { render, screen, initializeMocks } from '@src/testUtils';
2+
import { FeedbackBox } from './FeedbackBox';
3+
4+
jest.mock('../../../../../../../sharedComponents/ExpandableTextArea', () => jest.fn(({
5+
id, value, setContent, placeholder,
6+
}) => (
7+
<textarea id={id} value={value} placeholder={placeholder} onChange={e => setContent(e.target.value)} />
8+
)));
9+
10+
const answerWithFeedback = {
11+
id: 'A',
12+
title: 'Answer 1',
13+
correct: true,
14+
selectedFeedback: 'some feedback',
15+
unselectedFeedback: 'unselectedFeedback',
16+
problemType: 'sOMepRObleM',
17+
images: {},
18+
isLibrary: false,
19+
learningContextId: 'course+org+run',
20+
};
21+
22+
const props = {
23+
answer: answerWithFeedback,
24+
problemType: '',
25+
setAnswer: jest.fn(),
26+
setSelectedFeedback: jest.fn(),
27+
setUnselectedFeedback: jest.fn(),
28+
images: {},
29+
learningContextId: 'id',
30+
isLibrary: false,
31+
};
32+
33+
describe('FeedbackBox', () => {
34+
beforeEach(() => initializeMocks());
35+
36+
test('renders as expected with default props', () => {
37+
render(<FeedbackBox {...props} />);
38+
expect(screen.getByText(/Show following feedback when A/)).toBeInTheDocument();
39+
});
40+
test('renders as expected with a numeric input problem', () => {
41+
render(<FeedbackBox {...props} problemType="numericalresponse" />);
42+
expect(screen.getByText(/Show following feedback when A/)).toBeInTheDocument();
43+
expect(screen.getAllByText(/Show following feedback when A/)).toHaveLength(1);
44+
});
45+
test('renders as expected with a multi select problem', () => {
46+
render(<FeedbackBox {...props} problemType="choiceresponse" />);
47+
expect(screen.getAllByText(/Show following feedback when A/)).toHaveLength(2);
48+
});
49+
});

src/editors/containers/ProblemEditor/components/EditProblemView/AnswerWidget/components/Feedback/__snapshots__/FeedbackBox.test.jsx.snap

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

src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/CardSection.test.jsx

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { render, screen, initializeMocks } from '@src/testUtils';
2+
import CardSection from './CardSection';
3+
4+
describe('CardSection', () => {
5+
beforeEach(() => initializeMocks());
6+
test('renders children when open', () => {
7+
render(<CardSection summary="summary" isCardCollapsibleOpen><h1>Section Text</h1></CardSection>);
8+
expect(screen.getByText('Section Text')).toBeInTheDocument();
9+
expect(screen.queryByText('summary')).not.toBeInTheDocument();
10+
});
11+
12+
test('renders summary when closed', () => {
13+
render(<CardSection summary="summary" isCardCollapsibleOpen={false}><h1>Section Text</h1></CardSection>);
14+
expect(screen.queryByText('Section Text')).not.toBeInTheDocument();
15+
expect(screen.getByText('summary')).toBeInTheDocument();
16+
});
17+
18+
test('renders nothing when closed and not summary', () => {
19+
const { container } = render(<CardSection isCardCollapsibleOpen={false}><h1>Not showing text</h1></CardSection>);
20+
expect(screen.queryByText('Not showing text')).not.toBeInTheDocument();
21+
expect(container.textContent).toBe('');
22+
});
23+
});

src/editors/containers/ProblemEditor/components/EditProblemView/SettingsWidget/__snapshots__/CardSection.test.jsx.snap

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

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

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

0 commit comments

Comments
 (0)