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 ( / r e a l - w o r l d d a t a s e t / i) ) . toBeInTheDocument ( ) ;
26
+ expect ( screen . getByText ( / R e g r e s s i o n l i n e e q u a t i o n s / 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 : / S u b m i t / i } ) [ 0 ] ;
57
+ fireEvent . click ( submit1 ) ;
58
+
59
+ radios = screen . getAllByRole ( 'radio' ) ;
60
+ fireEvent . click ( radios [ 2 ] ) ;
61
+ let submit2 = screen . getAllByRole ( 'button' , { name : / S u b m i t / i } ) [ 1 ] ;
62
+ fireEvent . click ( submit2 ) ;
63
+
64
+ expect ( screen . getByRole ( 'button' , { name : / C o n t i n u e / 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 : / S u b m i t / 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 : / S u b m i t / i } ) [ 1 ] ;
86
+ fireEvent . click ( submit2 ) ;
87
+
88
+ const continueBtn = screen . getByRole ( 'button' , { name : / C o n t i n u e / i } ) ;
89
+ fireEvent . click ( continueBtn ) ;
90
+ expect ( mockHandleProgress ) . toHaveBeenCalledWith ( 2 ) ; ;
91
+ } ) ;
92
+ } ) ;
0 commit comments