@@ -196,18 +196,20 @@ describe('DiscussionsSettings', () => {
196
196
// content has been loaded - prior to proceeding with our expectations.
197
197
await waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
198
198
199
- userEvent . click ( queryByLabelText ( container , 'Select Piazza' ) ) ;
199
+ act ( async ( ) => {
200
+ userEvent . click ( queryByLabelText ( container , 'Select Piazza' ) ) ;
200
201
201
- userEvent . click ( getByRole ( container , 'button' , { name : 'Next' } ) ) ;
202
+ userEvent . click ( getByRole ( container , 'button' , { name : 'Next' } ) ) ;
202
203
203
- userEvent . click ( await findByRole ( container , 'button' , { name : 'Save' } ) ) ;
204
+ userEvent . click ( await findByRole ( container , 'button' , { name : 'Save' } ) ) ;
204
205
205
- // This is an important line that ensures the Close button has been removed, which implies that
206
- // the full screen modal has been closed following our click of Apply. Once this has happened,
207
- // then it's safe to proceed with our expectations.
208
- await waitFor ( ( ) => expect ( screen . queryByRole ( container , 'button' , { name : 'Close' } ) ) . toBeNull ( ) ) ;
206
+ // This is an important line that ensures the Close button has been removed, which implies that
207
+ // the full screen modal has been closed following our click of Apply. Once this has happened,
208
+ // then it's safe to proceed with our expectations.
209
+ await waitFor ( ( ) => expect ( screen . queryByRole ( container , 'button' , { name : 'Close' } ) ) . toBeNull ( ) ) ;
209
210
210
- setTimeout ( ( ) => expect ( window . location . pathname ) . toEqual ( `/course/${ courseId } /pages-and-resources` ) , 0 ) ;
211
+ await waitFor ( ( ) => expect ( window . location . pathname ) . toEqual ( `/course/${ courseId } /pages-and-resources` ) ) ;
212
+ } ) ;
211
213
} ) ;
212
214
213
215
test ( 'requires confirmation if changing provider' , async ( ) => {
@@ -219,16 +221,18 @@ describe('DiscussionsSettings', () => {
219
221
// content has been loaded - prior to proceeding with our expectations.
220
222
await waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
221
223
222
- userEvent . click ( getByRole ( container , 'checkbox' , { name : 'Select Discourse' } ) ) ;
223
- userEvent . click ( getByRole ( container , 'button' , { name : 'Next' } ) ) ;
224
+ act ( async ( ) => {
225
+ userEvent . click ( getByRole ( container , 'checkbox' , { name : 'Select Discourse' } ) ) ;
226
+ userEvent . click ( getByRole ( container , 'button' , { name : 'Next' } ) ) ;
224
227
225
- await findByRole ( container , 'button' , { name : 'Save' } ) ;
226
- userEvent . type ( getByRole ( container , 'textbox' , { name : 'Consumer Key' } ) , 'key' ) ;
227
- userEvent . type ( getByRole ( container , 'textbox' , { name : 'Consumer Secret' } ) , 'secret' ) ;
228
- userEvent . type ( getByRole ( container , 'textbox' , { name : 'Launch URL' } ) , 'http://example.test' ) ;
229
- userEvent . click ( getByRole ( container , 'button' , { name : 'Save' } ) ) ;
228
+ await findByRole ( container , 'button' , { name : 'Save' } ) ;
229
+ userEvent . type ( getByRole ( container , 'textbox' , { name : 'Consumer Key' } ) , 'key' ) ;
230
+ userEvent . type ( getByRole ( container , 'textbox' , { name : 'Consumer Secret' } ) , 'secret' ) ;
231
+ userEvent . type ( getByRole ( container , 'textbox' , { name : 'Launch URL' } ) , 'http://example.test' ) ;
232
+ userEvent . click ( getByRole ( container , 'button' , { name : 'Save' } ) ) ;
230
233
231
- setTimeout ( ( ) => expect ( screen . getByRole ( container , 'dialog' , { name : 'OK' } ) ) . toBeInTheDocument ( ) , 5000 ) ;
234
+ await waitFor ( ( ) => expect ( queryByRole ( container , 'dialog' , { name : 'OK' } ) ) . toBeInTheDocument ( ) ) ;
235
+ } ) ;
232
236
} ) ;
233
237
234
238
test ( 'can cancel confirmation' , async ( ) => {
@@ -248,20 +252,20 @@ describe('DiscussionsSettings', () => {
248
252
249
253
await waitFor ( ( ) => expect ( screen . queryByRole ( 'status' ) ) . toBeNull ( ) ) ;
250
254
251
- expect ( getByRole ( container , 'heading' , { name : 'Discourse' } ) ) . toBeInTheDocument ( ) ;
255
+ act ( async ( ) => {
256
+ expect ( await findByRole ( container , 'heading' , { name : 'Discourse' } ) ) . toBeInTheDocument ( ) ;
252
257
253
- userEvent . type ( getByRole ( container , 'textbox' , { name : 'Consumer Key' } ) , 'a' ) ;
254
- userEvent . type ( getByRole ( container , 'textbox' , { name : 'Consumer Secret' } ) , 'secret' ) ;
255
- userEvent . type ( getByRole ( container , 'textbox' , { name : 'Launch URL' } ) , 'http://example.test' ) ;
256
- userEvent . click ( getByRole ( container , 'button' , { name : 'Save' } ) ) ;
258
+ userEvent . type ( getByRole ( container , 'textbox' , { name : 'Consumer Key' } ) , 'a' ) ;
259
+ userEvent . type ( getByRole ( container , 'textbox' , { name : 'Consumer Secret' } ) , 'secret' ) ;
260
+ userEvent . type ( getByRole ( container , 'textbox' , { name : 'Launch URL' } ) , 'http://example.test' ) ;
261
+ userEvent . click ( getByRole ( container , 'button' , { name : 'Save' } ) ) ;
257
262
258
- setTimeout ( ( ) => {
259
263
waitFor ( ( ) => expect ( getByRole ( container , 'dialog' , { name : 'OK' } ) ) . toBeInTheDocument ( ) ) ;
260
264
userEvent . click ( getByRole ( container , 'button' , { name : 'Cancel' } ) ) ;
261
265
262
266
expect ( queryByRole ( container , 'dialog' , { name : 'Confirm' } ) ) . not . toBeInTheDocument ( ) ;
263
267
expect ( queryByRole ( container , 'dialog' , { name : 'Configure discussion' } ) ) ;
264
- } , 4000 ) ;
268
+ } ) ;
265
269
} ) ;
266
270
} ) ;
267
271
@@ -316,18 +320,16 @@ describe('DiscussionsSettings', () => {
316
320
await waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
317
321
318
322
// Apply causes an async action to take place
319
- await act ( ( ) => {
323
+ act ( async ( ) => {
320
324
userEvent . click ( queryByText ( container , appMessages . saveButton . defaultMessage ) ) ;
321
- } ) ;
325
+ await waitFor ( ( ) => expect ( axiosMock . history . post . length ) . toBe ( 1 ) ) ;
322
326
323
- setTimeout ( ( ) => {
324
- expect ( axiosMock . history . post . length ) . toBe ( 1 ) ;
325
327
expect ( queryByTestId ( container , 'appConfigForm' ) ) . toBeInTheDocument ( ) ;
326
- const alert = findByRole ( container , 'alert' ) ;
328
+ const alert = await findByRole ( container , 'alert' ) ;
327
329
expect ( alert ) . toBeInTheDocument ( ) ;
328
330
expect ( alert . textContent ) . toEqual ( expect . stringContaining ( 'We encountered a technical error when applying changes.' ) ) ;
329
331
expect ( alert . innerHTML ) . toEqual ( expect . stringContaining ( getConfig ( ) . SUPPORT_URL ) ) ;
330
- } , 4000 ) ;
332
+ } ) ;
331
333
} ) ;
332
334
} ) ;
333
335
@@ -369,20 +371,21 @@ describe('DiscussionsSettings', () => {
369
371
// content has been loaded - prior to proceeding with our expectations.
370
372
await waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
371
373
372
- userEvent . click ( getByRole ( container , 'button' , { name : 'Save' } ) ) ;
374
+ act ( async ( ) => {
375
+ userEvent . click ( getByRole ( container , 'button' , { name : 'Save' } ) ) ;
376
+
377
+ await waitFor ( ( ) => expect ( axiosMock . history . post . length ) . toBe ( 1 ) ) ;
373
378
374
- setTimeout ( ( ) => {
375
- expect ( axiosMock . history . post . length ) . toBe ( 1 ) ;
376
379
expect ( queryByTestId ( container , 'appList' ) ) . not . toBeInTheDocument ( ) ;
377
380
expect ( queryByTestId ( container , 'appConfigForm' ) ) . not . toBeInTheDocument ( ) ;
378
381
379
382
// We don't technically leave the route in this case, though the modal is hidden.
380
383
expect ( window . location . pathname ) . toEqual ( `/course/${ courseId } /pages-and-resources/discussion/configure/piazza` ) ;
381
384
382
- const alert = findByRole ( container , 'alert' ) ;
385
+ const alert = await findByRole ( container , 'alert' ) ;
383
386
expect ( alert ) . toBeInTheDocument ( ) ;
384
387
expect ( alert . textContent ) . toEqual ( expect . stringContaining ( 'You are not authorized to view this page.' ) ) ;
385
- } , 3000 ) ;
388
+ } ) ;
386
389
} ) ;
387
390
} ) ;
388
391
} ) ;
@@ -427,19 +430,21 @@ describe.each([
427
430
428
431
// This is an important line that ensures the spinner has been removed - and thus our main
429
432
// content has been loaded - prior to proceeding with our expectations.
430
- await waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
431
-
432
- userEvent . click ( queryByLabelText ( container , 'Select Piazza' ) ) ;
433
- userEvent . click ( queryByText ( container , messages . nextButton . defaultMessage ) ) ;
434
- await waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
435
-
436
- if ( showLTIConfig ) {
437
- expect ( queryByText ( container , ltiMessages . formInstructions . defaultMessage ) ) . toBeInTheDocument ( ) ;
438
- expect ( queryByTestId ( container , 'ltiConfigFields' ) ) . toBeInTheDocument ( ) ;
439
- } else {
440
- expect ( queryByText ( container , ltiMessages . formInstructions . defaultMessage ) ) . not . toBeInTheDocument ( ) ;
441
- expect ( queryByTestId ( container , 'ltiConfigFields' ) ) . not . toBeInTheDocument ( ) ;
442
- }
433
+ waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
434
+
435
+ act ( async ( ) => {
436
+ userEvent . click ( await screen . findByLabelText ( 'Select Piazza' ) ) ;
437
+ userEvent . click ( queryByText ( container , messages . nextButton . defaultMessage ) ) ;
438
+ waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
439
+
440
+ if ( showLTIConfig ) {
441
+ expect ( queryByText ( container , ltiMessages . formInstructions . defaultMessage ) ) . toBeInTheDocument ( ) ;
442
+ expect ( queryByTestId ( container , 'ltiConfigFields' ) ) . toBeInTheDocument ( ) ;
443
+ } else {
444
+ expect ( queryByText ( container , ltiMessages . formInstructions . defaultMessage ) ) . not . toBeInTheDocument ( ) ;
445
+ expect ( queryByTestId ( container , 'ltiConfigFields' ) ) . not . toBeInTheDocument ( ) ;
446
+ }
447
+ } ) ;
443
448
} ) ;
444
449
} ) ;
445
450
@@ -483,15 +488,19 @@ describe.each([
483
488
484
489
// This is an important line that ensures the spinner has been removed - and thus our main
485
490
// content has been loaded - prior to proceeding with our expectations.
486
- await waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
487
-
488
- userEvent . click ( queryByLabelText ( container , 'Select Piazza' ) ) ;
489
- userEvent . click ( queryByText ( container , messages . nextButton . defaultMessage ) ) ;
490
- await waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
491
- if ( enablePIISharing ) {
492
- expect ( queryByTestId ( container , 'piiSharingFields' ) ) . toBeInTheDocument ( ) ;
493
- } else {
494
- expect ( queryByTestId ( container , 'piiSharingFields' ) ) . not . toBeInTheDocument ( ) ;
495
- }
491
+ waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
492
+
493
+ act ( async ( ) => {
494
+ userEvent . click ( await screen . findByLabelText ( 'Select Piazza' ) ) ;
495
+ userEvent . click ( await screen . findByText ( messages . nextButton . defaultMessage ) ) ;
496
+
497
+ waitForElementToBeRemoved ( screen . getByRole ( 'status' ) ) ;
498
+ if ( enablePIISharing ) {
499
+ expect ( queryByTestId ( container , 'piiSharingFields' ) ) . toBeInTheDocument ( ) ;
500
+ } else {
501
+ expect ( queryByTestId ( container , 'piiSharingFields' ) ) . not . toBeInTheDocument ( ) ;
502
+ }
503
+ } ) ;
496
504
} ) ;
497
505
} ) ;
506
+
0 commit comments