Skip to content

Commit c6254d6

Browse files
authored
Merge pull request #906 from ccnmtl/ERD-463-multi
Add more tests
2 parents 63fe29e + c61f5f9 commit c6254d6

File tree

3 files changed

+179
-2
lines changed

3 files changed

+179
-2
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* global jest */
2+
import React from 'react';
3+
import { render, screen, fireEvent } from '@testing-library/react';
4+
import { MulticollinearityApply } from '../multicollinearityApply';
5+
6+
describe('MulticollinearityApply', () => {
7+
const mockHandleControls = jest.fn();
8+
const mockHandleProgress = jest.fn();
9+
const controls = [false, false];
10+
const submissionId = 1;
11+
12+
beforeEach(() => {
13+
jest.clearAllMocks();
14+
});
15+
16+
it('renders the real-world dataset prompt', () => {
17+
render(
18+
<MulticollinearityApply
19+
controls={controls}
20+
handleControls={mockHandleControls}
21+
handleProgress={mockHandleProgress}
22+
submissionId={submissionId}
23+
/>
24+
);
25+
expect(screen.getByText(/real-world dataset/i)).toBeInTheDocument();
26+
expect(screen.getByText(/Regression line equations/i))
27+
.toBeInTheDocument();
28+
});
29+
30+
it('calls handleControls when a checkbox is toggled', () => {
31+
render(
32+
<MulticollinearityApply
33+
controls={controls}
34+
handleControls={mockHandleControls}
35+
handleProgress={mockHandleProgress}
36+
submissionId={submissionId}
37+
/>
38+
);
39+
const checkboxes = screen.getAllByRole('checkbox');
40+
fireEvent.click(checkboxes[0]);
41+
expect(mockHandleControls).toHaveBeenCalled();
42+
});
43+
44+
it('shows Continue btn after both questions are answered correctly', () => {
45+
render(
46+
<MulticollinearityApply
47+
controls={controls}
48+
handleControls={mockHandleControls}
49+
handleProgress={mockHandleProgress}
50+
submissionId={submissionId}
51+
/>
52+
);
53+
// First question
54+
let radios = screen.getAllByRole('radio');
55+
fireEvent.click(radios[1]);
56+
let submit1 = screen.getAllByRole('button', { name: /Submit/i })[0];
57+
fireEvent.click(submit1);
58+
59+
radios = screen.getAllByRole('radio');
60+
fireEvent.click(radios[2]);
61+
let submit2 = screen.getAllByRole('button', { name: /Submit/i })[1];
62+
fireEvent.click(submit2);
63+
64+
expect(screen.getByRole('button', { name: /Continue/i }))
65+
.toBeInTheDocument();
66+
});
67+
it('calls handleProgress when Continue is clicked after questions', () => {
68+
render(
69+
<MulticollinearityApply
70+
controls={controls}
71+
handleControls={mockHandleControls}
72+
handleProgress={mockHandleProgress}
73+
submissionId={submissionId}
74+
/>
75+
);
76+
77+
let radios = screen.getAllByRole('radio');
78+
fireEvent.click(radios[1]); // correct answer for question 1
79+
let submit1 = screen.getAllByRole('button', { name: /Submit/i })[0];
80+
fireEvent.click(submit1);
81+
82+
// After submitting, re-query for the new radios and submit button
83+
radios = screen.getAllByRole('radio');
84+
fireEvent.click(radios[2]); // correct answer for question 2
85+
let submit2 = screen.getAllByRole('button', { name: /Submit/i })[1];
86+
fireEvent.click(submit2);
87+
88+
const continueBtn = screen.getByRole('button', { name: /Continue/i });
89+
fireEvent.click(continueBtn);
90+
expect(mockHandleProgress).toHaveBeenCalledWith(2);;
91+
});
92+
});

media/js/src/simulations/simulation3/tests/simulationThree.test.jsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,34 @@ describe('SimulationThree', () => {
2121
expect(screen.getByText(
2222
/Learning objectives: Multicollinearity/i)).toBeInTheDocument();
2323
});
24-
2524
it('shows progress list for Heteroskedasticity', () => {
2625
render(<SimulationThree />);
2726
expect(screen.getByText('Your progress:')).toBeInTheDocument();
2827
expect(screen.getByText('Learn')).toBeInTheDocument();
2928
expect(screen.getByText('Apply')).toBeInTheDocument();
3029
expect(screen.getByText('Assess')).toBeInTheDocument();
3130
});
32-
});
31+
it('shows progress list for Multicollinearity after switching', () => {
32+
render(<SimulationThree />);
33+
const multiBtn = screen.getByRole('button', {
34+
name: /Multicollinearity/i });
35+
fireEvent.click(multiBtn);
36+
expect(screen.getByText('Your progress:')).toBeInTheDocument();
37+
expect(screen.getByText('Learn')).toBeInTheDocument();
38+
expect(screen.getByText('Apply')).toBeInTheDocument();
39+
expect(screen.getByText('Assess')).toBeInTheDocument();
40+
});
41+
42+
it('renders simulation cards for both stages', () => {
43+
render(<SimulationThree />);
44+
// Heteroskedasticity card
45+
expect(screen.getByText(/Learning objectives: Heteroskedasticity/i))
46+
.toBeInTheDocument();
47+
// Switch to Multicollinearity and check card
48+
const multiBtn = screen.getByRole('button', {
49+
name: /Multicollinearity/i });
50+
fireEvent.click(multiBtn);
51+
expect(screen.getByText(/Learning objectives: Multicollinearity/i))
52+
.toBeInTheDocument();
53+
});
54+
});
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* global jest */
2+
import React from 'react';
3+
import { render, screen, fireEvent } from '@testing-library/react';
4+
import { WhatIsMulticollinearity } from '../whatIsMulticollinearity';
5+
6+
describe('WhatIsMulticollinearity', () => {
7+
const mockHandleControls = jest.fn();
8+
const mockHandleProgress = jest.fn();
9+
const controls = [false, false];
10+
11+
it('renders the definition and prompt', () => {
12+
render(
13+
<WhatIsMulticollinearity
14+
controls={controls}
15+
handleControls={mockHandleControls}
16+
handleProgress={mockHandleProgress}
17+
/>
18+
);
19+
expect(screen.getByText(/definition of multicollinearity/i))
20+
.toBeInTheDocument();
21+
expect(screen.getByRole('button', {
22+
name: /Definition: Multicollinearity/i })).toBeInTheDocument();
23+
});
24+
25+
it('renders the glossary button', () => {
26+
render(
27+
<WhatIsMulticollinearity
28+
controls={controls}
29+
handleControls={mockHandleControls}
30+
handleProgress={mockHandleProgress}
31+
/>
32+
);
33+
expect(screen.getByRole('button', { name: /Glossary/i }))
34+
.toBeInTheDocument();
35+
});
36+
37+
it('calls handleProgress when Continue to Real dataset is clicked', () => {
38+
render(
39+
<WhatIsMulticollinearity
40+
controls={controls}
41+
handleControls={mockHandleControls}
42+
handleProgress={mockHandleProgress}
43+
/>
44+
);
45+
const continueBtn = screen.getByRole('button', {
46+
name: /Continue to Real dataset/i });
47+
fireEvent.click(continueBtn);
48+
expect(mockHandleProgress).toHaveBeenCalledWith(1);
49+
});
50+
51+
it('calls handleControls when a checkbox is toggled', () => {
52+
render(
53+
<WhatIsMulticollinearity
54+
controls={controls}
55+
handleControls={mockHandleControls}
56+
handleProgress={mockHandleProgress}
57+
/>
58+
);
59+
const x2Checkbox = screen.getByLabelText(/x_1\\ and\\ x_2/i);
60+
fireEvent.click(x2Checkbox);
61+
expect(mockHandleControls).toHaveBeenCalled();
62+
});
63+
});

0 commit comments

Comments
 (0)