11import { ComponentProps } from 'react' ;
2- import { fireEvent , render , RenderResult } from 'test-utils' ;
2+ import { fireEvent , render , RenderResult , waitFor } from 'test-utils' ;
33
44import AssessmentForm from '..' ;
55
@@ -61,143 +61,173 @@ beforeEach(() => {
6161} ) ;
6262
6363describe ( '<AssessmentForm />' , ( ) => {
64- it ( 'renders assessment details sections options' , ( ) => {
64+ it ( 'renders assessment details sections options' , async ( ) => {
6565 renderForm ( ) ;
6666
67- expect ( form . getByText ( 'Assessment details' ) ) . toBeVisible ( ) ;
68- expect ( form . getByLabelText ( 'Starts at *' ) ) . toBeVisible ( ) ;
69- expect ( form . getByLabelText ( 'Ends at' ) ) . toBeVisible ( ) ;
70- expect ( form . getByLabelText ( 'Title *' ) ) . toHaveValue ( INITIAL_VALUES . title ) ;
71- expect ( form . getByText ( 'Description' ) ) . toBeVisible ( ) ;
72- expect ( form . getByDisplayValue ( INITIAL_VALUES . description ) ) . toBeVisible ( ) ;
67+ await waitFor ( ( ) => {
68+ expect ( form . getByText ( 'Assessment details' ) ) . toBeVisible ( ) ;
69+ expect ( form . getByLabelText ( 'Starts at *' ) ) . toBeVisible ( ) ;
70+ expect ( form . getByLabelText ( 'Ends at' ) ) . toBeVisible ( ) ;
71+ expect ( form . getByLabelText ( 'Title *' ) ) . toHaveValue ( INITIAL_VALUES . title ) ;
72+ expect ( form . getByText ( 'Description' ) ) . toBeVisible ( ) ;
73+ expect ( form . getByDisplayValue ( INITIAL_VALUES . description ) ) . toBeVisible ( ) ;
74+ } ) ;
7375 } ) ;
7476
75- it ( 'renders grading section options' , ( ) => {
77+ it ( 'renders grading section options' , async ( ) => {
7678 renderForm ( ) ;
7779
78- expect ( form . getByText ( 'Grading' ) ) . toBeVisible ( ) ;
79- expect ( form . getByText ( 'Grading mode' ) ) . toBeVisible ( ) ;
80+ await waitFor ( ( ) => {
81+ expect ( form . getByText ( 'Grading' ) ) . toBeVisible ( ) ;
82+ expect ( form . getByText ( 'Grading mode' ) ) . toBeVisible ( ) ;
8083
81- expect ( form . getByText ( 'Autograded' ) ) . toBeVisible ( ) ;
82- expect ( form . getByDisplayValue ( 'autograded' ) ) . not . toBeChecked ( ) ;
84+ expect ( form . getByText ( 'Autograded' ) ) . toBeVisible ( ) ;
85+ expect ( form . getByDisplayValue ( 'autograded' ) ) . not . toBeChecked ( ) ;
8386
84- expect ( form . getByText ( 'Manual' ) ) . toBeVisible ( ) ;
85- expect ( form . getByDisplayValue ( 'manual' ) ) . toBeChecked ( ) ;
87+ expect ( form . getByText ( 'Manual' ) ) . toBeVisible ( ) ;
88+ expect ( form . getByDisplayValue ( 'manual' ) ) . toBeChecked ( ) ;
8689
87- expect ( form . getByLabelText ( 'Public test cases' ) ) . toBeChecked ( ) ;
88- expect ( form . getByLabelText ( 'Private test cases' ) ) . toBeChecked ( ) ;
89- expect ( form . getByLabelText ( 'Evaluation test cases' ) ) . not . toBeChecked ( ) ;
90+ expect ( form . getByLabelText ( 'Public test cases' ) ) . toBeChecked ( ) ;
91+ expect ( form . getByLabelText ( 'Private test cases' ) ) . toBeChecked ( ) ;
92+ expect ( form . getByLabelText ( 'Evaluation test cases' ) ) . not . toBeChecked ( ) ;
9093
91- expect (
92- form . getByLabelText ( 'Enable delayed grade publication' ) ,
93- ) . not . toBeChecked ( ) ;
94+ expect (
95+ form . getByLabelText ( 'Enable delayed grade publication' ) ,
96+ ) . not . toBeChecked ( ) ;
97+ } ) ;
9498 } ) ;
9599
96- it ( 'renders answers and test cases section options' , ( ) => {
100+ it ( 'renders answers and test cases section options' , async ( ) => {
97101 renderForm ( ) ;
98102
99- expect ( form . getByText ( 'Answers and test cases' ) ) . toBeVisible ( ) ;
100- expect ( form . getByLabelText ( 'Allow to skip steps' ) ) . not . toBeChecked ( ) ;
101- expect (
102- form . getByLabelText ( 'Allow submission with incorrect answers' ) ,
103- ) . not . toBeChecked ( ) ;
104- expect ( form . getByLabelText ( 'Show private test cases' ) ) . not . toBeChecked ( ) ;
105- expect ( form . getByLabelText ( 'Show evaluation test cases' ) ) . not . toBeChecked ( ) ;
106- expect ( form . getByLabelText ( 'Show MCQ/MRQ solution(s)' ) ) . not . toBeChecked ( ) ;
103+ await waitFor ( ( ) => {
104+ expect ( form . getByText ( 'Answers and test cases' ) ) . toBeVisible ( ) ;
105+ expect ( form . getByLabelText ( 'Allow to skip steps' ) ) . not . toBeChecked ( ) ;
106+ expect (
107+ form . getByLabelText ( 'Allow submission with incorrect answers' ) ,
108+ ) . not . toBeChecked ( ) ;
109+ expect ( form . getByLabelText ( 'Show private test cases' ) ) . not . toBeChecked ( ) ;
110+ expect (
111+ form . getByLabelText ( 'Show evaluation test cases' ) ,
112+ ) . not . toBeChecked ( ) ;
113+ expect ( form . getByLabelText ( 'Show MCQ/MRQ solution(s)' ) ) . not . toBeChecked ( ) ;
114+ } ) ;
107115 } ) ;
108116
109- it ( 'renders organization section options' , ( ) => {
117+ it ( 'renders organization section options' , async ( ) => {
110118 renderForm ( ) ;
111119
112- expect ( form . getByText ( 'Organization' ) ) . toBeVisible ( ) ;
113- expect ( form . getByText ( 'Single Page' ) ) . toBeVisible ( ) ;
120+ await waitFor ( ( ) => {
121+ expect ( form . getByText ( 'Organization' ) ) . toBeVisible ( ) ;
122+ expect ( form . getByText ( 'Single Page' ) ) . toBeVisible ( ) ;
123+ } ) ;
114124 } ) ;
115125
116- it ( 'renders exams and access control section options' , ( ) => {
126+ it ( 'renders exams and access control section options' , async ( ) => {
117127 renderForm ( ) ;
118128
119- expect ( form . getByText ( 'Exams and access control' ) ) . toBeVisible ( ) ;
120- expect (
121- form . getByLabelText ( 'Block students from viewing finalized submissions' ) ,
122- ) . not . toBeChecked ( ) ;
123- expect ( form . getByLabelText ( 'Show MCQ submit result' ) ) . not . toBeChecked ( ) ;
124- expect ( form . getByLabelText ( 'Enable password protection' ) ) . not . toBeChecked ( ) ;
129+ await waitFor ( ( ) => {
130+ expect ( form . getByText ( 'Exams and access control' ) ) . toBeVisible ( ) ;
131+ expect (
132+ form . getByLabelText (
133+ 'Block students from viewing finalized submissions' ,
134+ ) ,
135+ ) . not . toBeChecked ( ) ;
136+ expect ( form . getByLabelText ( 'Show MCQ submit result' ) ) . not . toBeChecked ( ) ;
137+ expect (
138+ form . getByLabelText ( 'Enable password protection' ) ,
139+ ) . not . toBeChecked ( ) ;
140+ } ) ;
125141 } ) ;
126142
127- it ( 'does not render gamified options when course is not gamified' , ( ) => {
143+ it ( 'does not render gamified options when course is not gamified' , async ( ) => {
128144 renderForm ( ) ;
129145
130- expect ( form . queryByText ( 'Gamification' ) ) . not . toBeInTheDocument ( ) ;
131- expect ( form . queryByLabelText ( 'Bonus ends at' ) ) . not . toBeInTheDocument ( ) ;
132- expect ( form . queryByLabelText ( 'Base EXP' ) ) . not . toBeInTheDocument ( ) ;
133- expect ( form . queryByLabelText ( 'Time Bonus EXP' ) ) . not . toBeInTheDocument ( ) ;
146+ await waitFor ( ( ) => {
147+ expect ( form . queryByText ( 'Gamification' ) ) . not . toBeInTheDocument ( ) ;
148+ expect ( form . queryByLabelText ( 'Bonus ends at' ) ) . not . toBeInTheDocument ( ) ;
149+ expect ( form . queryByLabelText ( 'Base EXP' ) ) . not . toBeInTheDocument ( ) ;
150+ expect ( form . queryByLabelText ( 'Time Bonus EXP' ) ) . not . toBeInTheDocument ( ) ;
151+ } ) ;
134152 } ) ;
135153
136- it ( 'renders gamified options when course is gamified' , ( ) => {
154+ it ( 'renders gamified options when course is gamified' , async ( ) => {
137155 props . gamified = true ;
138156 renderForm ( ) ;
139157
140- expect ( form . getByText ( 'Gamification' ) ) . toBeVisible ( ) ;
141- expect ( form . getByLabelText ( 'Bonus ends at' ) ) . toBeVisible ( ) ;
142- expect ( form . getByLabelText ( 'Base EXP' ) ) . toHaveValue (
143- INITIAL_VALUES . base_exp . toString ( ) ,
144- ) ;
145- expect ( form . getByLabelText ( 'Time Bonus EXP' ) ) . toHaveValue (
146- INITIAL_VALUES . time_bonus_exp . toString ( ) ,
147- ) ;
158+ await waitFor ( ( ) => {
159+ expect ( form . getByText ( 'Gamification' ) ) . toBeVisible ( ) ;
160+ expect ( form . getByLabelText ( 'Bonus ends at' ) ) . toBeVisible ( ) ;
161+ expect ( form . getByLabelText ( 'Base EXP' ) ) . toHaveValue (
162+ INITIAL_VALUES . base_exp . toString ( ) ,
163+ ) ;
164+ expect ( form . getByLabelText ( 'Time Bonus EXP' ) ) . toHaveValue (
165+ INITIAL_VALUES . time_bonus_exp . toString ( ) ,
166+ ) ;
167+ } ) ;
148168 } ) ;
149169
150- it ( 'does not render editing options when rendered in new assessment page' , ( ) => {
151- expect ( form . queryByText ( 'Visibility' ) ) . not . toBeInTheDocument ( ) ;
152- expect ( form . queryByText ( 'Published' ) ) . not . toBeInTheDocument ( ) ;
153- expect ( form . queryByText ( 'Draft' ) ) . not . toBeInTheDocument ( ) ;
154- expect ( form . queryByText ( 'Files' ) ) . not . toBeInTheDocument ( ) ;
155- expect ( form . queryByText ( 'Add Files' ) ) . not . toBeInTheDocument ( ) ;
156- expect ( form . queryByText ( 'Unlock conditions' ) ) . not . toBeInTheDocument ( ) ;
157- expect ( form . queryByText ( 'Add a condition' ) ) . not . toBeInTheDocument ( ) ;
170+ it ( 'does not render editing options when rendered in new assessment page' , async ( ) => {
171+ await waitFor ( ( ) => {
172+ expect ( form . queryByText ( 'Visibility' ) ) . not . toBeInTheDocument ( ) ;
173+ expect ( form . queryByText ( 'Published' ) ) . not . toBeInTheDocument ( ) ;
174+ expect ( form . queryByText ( 'Draft' ) ) . not . toBeInTheDocument ( ) ;
175+ expect ( form . queryByText ( 'Files' ) ) . not . toBeInTheDocument ( ) ;
176+ expect ( form . queryByText ( 'Add Files' ) ) . not . toBeInTheDocument ( ) ;
177+ expect ( form . queryByText ( 'Unlock conditions' ) ) . not . toBeInTheDocument ( ) ;
178+ expect ( form . queryByText ( 'Add a condition' ) ) . not . toBeInTheDocument ( ) ;
179+ } ) ;
158180 } ) ;
159181
160- it ( 'renders editing options when rendered in edit assessment page' , ( ) => {
182+ it ( 'renders editing options when rendered in edit assessment page' , async ( ) => {
161183 props . editing = true ;
162184 renderForm ( ) ;
163185
164- expect ( form . getByText ( 'Visibility' ) ) . toBeVisible ( ) ;
165- expect ( form . getByText ( 'Published' ) ) . toBeVisible ( ) ;
166- expect ( form . getByDisplayValue ( 'published' ) ) . not . toBeChecked ( ) ;
167- expect ( form . getByText ( 'Draft' ) ) . toBeVisible ( ) ;
168- expect ( form . getByDisplayValue ( 'draft' ) ) . toBeChecked ( ) ;
169- expect ( form . getByText ( 'Files' ) ) . toBeVisible ( ) ;
170- expect ( form . getByText ( 'Add Files' ) ) . toBeVisible ( ) ;
171- expect ( form . queryByText ( 'Unlock conditions' ) ) . not . toBeInTheDocument ( ) ;
172- expect ( form . queryByText ( 'Add a condition' ) ) . not . toBeInTheDocument ( ) ;
186+ await waitFor ( ( ) => {
187+ expect ( form . getByText ( 'Visibility' ) ) . toBeVisible ( ) ;
188+ expect ( form . getByText ( 'Published' ) ) . toBeVisible ( ) ;
189+ expect ( form . getByDisplayValue ( 'published' ) ) . not . toBeChecked ( ) ;
190+ expect ( form . getByText ( 'Draft' ) ) . toBeVisible ( ) ;
191+ expect ( form . getByDisplayValue ( 'draft' ) ) . toBeChecked ( ) ;
192+ expect ( form . getByText ( 'Files' ) ) . toBeVisible ( ) ;
193+ expect ( form . getByText ( 'Add Files' ) ) . toBeVisible ( ) ;
194+ expect ( form . queryByText ( 'Unlock conditions' ) ) . not . toBeInTheDocument ( ) ;
195+ expect ( form . queryByText ( 'Add a condition' ) ) . not . toBeInTheDocument ( ) ;
196+ } ) ;
173197
174198 props . gamified = true ;
175199 renderForm ( ) ;
176200
177- expect ( form . getByText ( 'Unlock conditions' ) ) . toBeVisible ( ) ;
178- expect ( form . getByText ( 'Add a condition' ) ) . toBeVisible ( ) ;
201+ await waitFor ( ( ) => {
202+ expect ( form . getByText ( 'Unlock conditions' ) ) . toBeVisible ( ) ;
203+ expect ( form . getByText ( 'Add a condition' ) ) . toBeVisible ( ) ;
204+ } ) ;
179205 } ) ;
180206
181- it ( 'prevents grading mode switching when there are submissions' , ( ) => {
207+ it ( 'prevents grading mode switching when there are submissions' , async ( ) => {
182208 props . modeSwitching = false ;
183209 renderForm ( ) ;
184210
185- expect ( form . getByDisplayValue ( 'autograded' ) ) . toBeDisabled ( ) ;
186- expect ( form . getByDisplayValue ( 'manual' ) ) . toBeDisabled ( ) ;
211+ await waitFor ( ( ) => {
212+ expect ( form . getByDisplayValue ( 'autograded' ) ) . toBeDisabled ( ) ;
213+ expect ( form . getByDisplayValue ( 'manual' ) ) . toBeDisabled ( ) ;
214+ } ) ;
187215 } ) ;
188216
189- it ( 'disables unavailable options in autograded mode' , ( ) => {
217+ it ( 'disables unavailable options in autograded mode' , async ( ) => {
190218 renderForm ( ) ;
191219
192- expect ( form . getByLabelText ( 'Allow to skip steps' ) ) . toBeDisabled ( ) ;
193- expect (
194- form . getByLabelText ( 'Allow submission with incorrect answers' ) ,
195- ) . toBeDisabled ( ) ;
196- expect (
197- form . getByLabelText ( 'Enable delayed grade publication' ) ,
198- ) . toBeEnabled ( ) ;
199- expect ( form . getByLabelText ( 'Show MCQ submit result' ) ) . toBeDisabled ( ) ;
200- expect ( form . getByLabelText ( 'Enable password protection' ) ) . toBeEnabled ( ) ;
220+ await waitFor ( ( ) => {
221+ expect ( form . getByLabelText ( 'Allow to skip steps' ) ) . toBeDisabled ( ) ;
222+ expect (
223+ form . getByLabelText ( 'Allow submission with incorrect answers' ) ,
224+ ) . toBeDisabled ( ) ;
225+ expect (
226+ form . getByLabelText ( 'Enable delayed grade publication' ) ,
227+ ) . toBeEnabled ( ) ;
228+ expect ( form . getByLabelText ( 'Show MCQ submit result' ) ) . toBeDisabled ( ) ;
229+ expect ( form . getByLabelText ( 'Enable password protection' ) ) . toBeEnabled ( ) ;
230+ } ) ;
201231
202232 const autogradedRadio = form . getByDisplayValue ( 'autograded' ) ;
203233 fireEvent . click ( autogradedRadio ) ;
@@ -213,18 +243,20 @@ describe('<AssessmentForm />', () => {
213243 expect ( form . getByLabelText ( 'Enable password protection' ) ) . toBeDisabled ( ) ;
214244 } ) ;
215245
216- it ( 'handles password protection options' , ( ) => {
246+ it ( 'handles password protection options' , async ( ) => {
217247 renderForm ( ) ;
218248
219- expect (
220- form . queryByLabelText ( 'Assessment password *' ) ,
221- ) . not . toBeInTheDocument ( ) ;
222- expect (
223- form . queryByLabelText ( 'Enable session protection' ) ,
224- ) . not . toBeInTheDocument ( ) ;
225- expect (
226- form . queryByLabelText ( 'Session unlock password *' ) ,
227- ) . not . toBeInTheDocument ( ) ;
249+ await waitFor ( ( ) => {
250+ expect (
251+ form . queryByLabelText ( 'Assessment password *' ) ,
252+ ) . not . toBeInTheDocument ( ) ;
253+ expect (
254+ form . queryByLabelText ( 'Enable session protection' ) ,
255+ ) . not . toBeInTheDocument ( ) ;
256+ expect (
257+ form . queryByLabelText ( 'Session unlock password *' ) ,
258+ ) . not . toBeInTheDocument ( ) ;
259+ } ) ;
228260
229261 const passwordCheckbox = form . getByLabelText ( 'Enable password protection' ) ;
230262 expect ( passwordCheckbox ) . toBeEnabled ( ) ;
@@ -260,19 +292,25 @@ describe('<AssessmentForm />', () => {
260292 expect ( browserAuthorizationCheckbox ) . toBeChecked ( ) ;
261293 } ) ;
262294
263- it ( 'renders personalised timelines options when enabled' , ( ) => {
295+ it ( 'renders personalised timelines options when enabled' , async ( ) => {
264296 renderForm ( ) ;
265297
266- expect ( form . queryByLabelText ( 'Has personal times' ) ) . not . toBeInTheDocument ( ) ;
267- expect (
268- form . queryByLabelText ( 'Affects personal times' ) ,
269- ) . not . toBeInTheDocument ( ) ;
298+ await waitFor ( ( ) => {
299+ expect (
300+ form . queryByLabelText ( 'Has personal times' ) ,
301+ ) . not . toBeInTheDocument ( ) ;
302+ expect (
303+ form . queryByLabelText ( 'Affects personal times' ) ,
304+ ) . not . toBeInTheDocument ( ) ;
305+ } ) ;
270306
271307 props . showPersonalizedTimelineFeatures = true ;
272308 renderForm ( ) ;
273309
274- expect ( form . getByLabelText ( 'Has personal times' ) ) . toBeEnabled ( ) ;
275- expect ( form . getByLabelText ( 'Affects personal times' ) ) . toBeEnabled ( ) ;
310+ await waitFor ( ( ) => {
311+ expect ( form . getByLabelText ( 'Has personal times' ) ) . toBeEnabled ( ) ;
312+ expect ( form . getByLabelText ( 'Affects personal times' ) ) . toBeEnabled ( ) ;
313+ } ) ;
276314 } ) ;
277315
278316 // Randomized Assessment is temporarily hidden (PR#5406)
0 commit comments