1
1
import { debug , getClient , setCurrentClient } from '@sentry/core' ;
2
- import { render } from '@testing-library/react-native' ;
2
+ import { act , render , waitFor } from '@testing-library/react-native' ;
3
3
import * as React from 'react' ;
4
4
import { Appearance , Text } from 'react-native' ;
5
5
import { defaultConfiguration } from '../../src/js/feedback/defaults' ;
@@ -33,7 +33,7 @@ describe('FeedbackWidgetManager', () => {
33
33
resetFeedbackWidgetManager ( ) ;
34
34
} ) ;
35
35
36
- it ( 'showFeedbackWidget displays the form when FeedbackWidgetProvider is used' , ( ) => {
36
+ it ( 'showFeedbackWidget displays the form when FeedbackWidgetProvider is used' , async ( ) => {
37
37
mockedIsModalSupported . mockReturnValue ( true ) ;
38
38
const { getByText, getByTestId } = render (
39
39
< FeedbackWidgetProvider >
@@ -43,7 +43,9 @@ describe('FeedbackWidgetManager', () => {
43
43
44
44
showFeedbackWidget ( ) ;
45
45
46
- expect ( getByTestId ( 'feedback-form-modal' ) ) . toBeTruthy ( ) ;
46
+ await waitFor ( ( ) => {
47
+ expect ( getByTestId ( 'feedback-form-modal' ) ) . toBeTruthy ( ) ;
48
+ } ) ;
47
49
expect ( getByText ( 'App Components' ) ) . toBeTruthy ( ) ;
48
50
} ) ;
49
51
@@ -70,7 +72,7 @@ describe('FeedbackWidgetManager', () => {
70
72
} ) . not . toThrow ( ) ;
71
73
} ) ;
72
74
73
- it ( 'showFeedbackWidget displays the form with the feedbackIntegration options' , ( ) => {
75
+ it ( 'showFeedbackWidget displays the form with the feedbackIntegration options' , async ( ) => {
74
76
mockedIsModalSupported . mockReturnValue ( true ) ;
75
77
const { getByPlaceholderText, getByText } = render (
76
78
< FeedbackWidgetProvider >
@@ -86,11 +88,13 @@ describe('FeedbackWidgetManager', () => {
86
88
87
89
showFeedbackWidget ( ) ;
88
90
89
- expect ( getByPlaceholderText ( 'Custom Message Placeholder' ) ) . toBeTruthy ( ) ;
91
+ await waitFor ( ( ) => {
92
+ expect ( getByPlaceholderText ( 'Custom Message Placeholder' ) ) . toBeTruthy ( ) ;
93
+ } ) ;
90
94
expect ( getByText ( 'Custom Submit Button' ) ) . toBeTruthy ( ) ;
91
95
} ) ;
92
96
93
- it ( 'showFeedbackWidget displays the form with the feedbackIntegration options merged with the defaults' , ( ) => {
97
+ it ( 'showFeedbackWidget displays the form with the feedbackIntegration options merged with the defaults' , async ( ) => {
94
98
mockedIsModalSupported . mockReturnValue ( true ) ;
95
99
const { getByPlaceholderText, getByText, queryByText } = render (
96
100
< FeedbackWidgetProvider >
@@ -105,8 +109,10 @@ describe('FeedbackWidgetManager', () => {
105
109
106
110
showFeedbackWidget ( ) ;
107
111
108
- expect ( queryByText ( defaultConfiguration . submitButtonLabel ) ) . toBeFalsy ( ) ; // overridden value
109
- expect ( getByText ( 'Custom Submit Button' ) ) . toBeTruthy ( ) ; // overridden value
112
+ await waitFor ( ( ) => {
113
+ expect ( queryByText ( defaultConfiguration . submitButtonLabel ) ) . toBeFalsy ( ) ; // overridden value
114
+ expect ( getByText ( 'Custom Submit Button' ) ) . toBeTruthy ( ) ; // overridden value
115
+ } ) ;
110
116
expect ( getByPlaceholderText ( defaultConfiguration . messagePlaceholder ) ) . toBeTruthy ( ) ; // default configuration value
111
117
} ) ;
112
118
@@ -161,7 +167,7 @@ describe('FeedbackButtonManager', () => {
161
167
} ) ;
162
168
} ) ;
163
169
164
- it ( 'showFeedbackButton displays the button when FeedbackWidgetProvider is used' , ( ) => {
170
+ it ( 'showFeedbackButton displays the button when FeedbackWidgetProvider is used' , async ( ) => {
165
171
const { getByText } = render (
166
172
< FeedbackWidgetProvider >
167
173
< Text > App Components</ Text >
@@ -170,7 +176,9 @@ describe('FeedbackButtonManager', () => {
170
176
171
177
showFeedbackButton ( ) ;
172
178
173
- expect ( getByText ( 'Report a Bug' ) ) . toBeTruthy ( ) ;
179
+ await waitFor ( ( ) => {
180
+ expect ( getByText ( 'Report a Bug' ) ) . toBeTruthy ( ) ;
181
+ } )
174
182
} ) ;
175
183
176
184
it ( 'hideFeedbackButton hides the button' , ( ) => {
@@ -216,7 +224,7 @@ describe('FeedbackButtonManager', () => {
216
224
expect ( getClient ( ) . getIntegrationByName ( AUTO_INJECT_FEEDBACK_BUTTON_INTEGRATION_NAME ) ) . toBeDefined ( ) ;
217
225
} ) ;
218
226
219
- it ( 'the Feedback Widget matches the snapshot with default configuration and system light theme' , ( ) => {
227
+ it ( 'the Feedback Widget matches the snapshot with default configuration and system light theme' , async ( ) => {
220
228
mockedIsModalSupported . mockReturnValue ( true ) ;
221
229
const { toJSON } = render (
222
230
< FeedbackWidgetProvider >
@@ -226,12 +234,14 @@ describe('FeedbackButtonManager', () => {
226
234
227
235
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
228
236
229
- showFeedbackWidget ( ) ;
237
+ await act ( async ( ) => {
238
+ showFeedbackWidget ( ) ;
239
+ } ) ;
230
240
231
241
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
232
242
} ) ;
233
243
234
- it ( 'the Feedback Widget matches the snapshot with default configuration and system dark theme' , ( ) => {
244
+ it ( 'the Feedback Widget matches the snapshot with default configuration and system dark theme' , async ( ) => {
235
245
mockedIsModalSupported . mockReturnValue ( true ) ;
236
246
const { toJSON } = render (
237
247
< FeedbackWidgetProvider >
@@ -241,12 +251,14 @@ describe('FeedbackButtonManager', () => {
241
251
242
252
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
243
253
244
- showFeedbackWidget ( ) ;
254
+ await act ( async ( ) => {
255
+ showFeedbackWidget ( ) ;
256
+ } ) ;
245
257
246
258
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
247
259
} ) ;
248
260
249
- it ( 'the Feedback Widget matches the snapshot with default configuration and dynamically changed theme' , ( ) => {
261
+ it ( 'the Feedback Widget matches the snapshot with default configuration and dynamically changed theme' , async ( ) => {
250
262
const component = (
251
263
< FeedbackWidgetProvider >
252
264
< Text > App Components</ Text >
@@ -258,15 +270,19 @@ describe('FeedbackButtonManager', () => {
258
270
259
271
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
260
272
261
- showFeedbackWidget ( ) ;
273
+ await act ( async ( ) => {
274
+ showFeedbackWidget ( ) ;
275
+ } ) ;
262
276
263
277
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
264
- listener ( { colorScheme : 'dark' } ) ;
278
+ await act ( async ( ) => {
279
+ listener ( { colorScheme : 'dark' } ) ;
280
+ } )
265
281
266
282
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
267
283
} ) ;
268
284
269
- it ( 'the Feedback Widget matches the snapshot with custom light theme' , ( ) => {
285
+ it ( 'the Feedback Widget matches the snapshot with custom light theme' , async ( ) => {
270
286
mockedIsModalSupported . mockReturnValue ( true ) ;
271
287
const { toJSON } = render (
272
288
< FeedbackWidgetProvider >
@@ -283,12 +299,14 @@ describe('FeedbackButtonManager', () => {
283
299
} ) ;
284
300
getClient ( ) ?. addIntegration ( integration ) ;
285
301
286
- showFeedbackWidget ( ) ;
302
+ await act ( async ( ) => {
303
+ showFeedbackWidget ( ) ;
304
+ } ) ;
287
305
288
306
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
289
307
} ) ;
290
308
291
- it ( 'the Feedback Widget matches the snapshot with custom dark theme' , ( ) => {
309
+ it ( 'the Feedback Widget matches the snapshot with custom dark theme' , async ( ) => {
292
310
mockedIsModalSupported . mockReturnValue ( true ) ;
293
311
const { toJSON } = render (
294
312
< FeedbackWidgetProvider >
@@ -305,12 +323,14 @@ describe('FeedbackButtonManager', () => {
305
323
} ) ;
306
324
getClient ( ) ?. addIntegration ( integration ) ;
307
325
308
- showFeedbackWidget ( ) ;
326
+ await act ( async ( ) => {
327
+ showFeedbackWidget ( ) ;
328
+ } ) ;
309
329
310
330
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
311
331
} ) ;
312
332
313
- it ( 'the Feedback Widget matches the snapshot with system light custom theme' , ( ) => {
333
+ it ( 'the Feedback Widget matches the snapshot with system light custom theme' , async ( ) => {
314
334
mockedIsModalSupported . mockReturnValue ( true ) ;
315
335
const { toJSON } = render (
316
336
< FeedbackWidgetProvider >
@@ -329,12 +349,14 @@ describe('FeedbackButtonManager', () => {
329
349
330
350
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
331
351
332
- showFeedbackWidget ( ) ;
352
+ await act ( async ( ) => {
353
+ showFeedbackWidget ( ) ;
354
+ } ) ;
333
355
334
356
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
335
357
} ) ;
336
358
337
- it ( 'the Feedback Widget matches the snapshot with system dark custom theme' , ( ) => {
359
+ it ( 'the Feedback Widget matches the snapshot with system dark custom theme' , async ( ) => {
338
360
mockedIsModalSupported . mockReturnValue ( true ) ;
339
361
const { toJSON } = render (
340
362
< FeedbackWidgetProvider >
@@ -353,12 +375,14 @@ describe('FeedbackButtonManager', () => {
353
375
354
376
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
355
377
356
- showFeedbackWidget ( ) ;
378
+ await act ( async ( ) => {
379
+ showFeedbackWidget ( ) ;
380
+ } ) ;
357
381
358
382
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
359
383
} ) ;
360
384
361
- it ( 'the Feedback Button matches the snapshot with default configuration and system light theme' , ( ) => {
385
+ it ( 'the Feedback Button matches the snapshot with default configuration and system light theme' , async ( ) => {
362
386
mockedIsModalSupported . mockReturnValue ( true ) ;
363
387
const { toJSON } = render (
364
388
< FeedbackWidgetProvider >
@@ -368,12 +392,14 @@ describe('FeedbackButtonManager', () => {
368
392
369
393
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
370
394
371
- showFeedbackButton ( ) ;
395
+ await act ( async ( ) => {
396
+ showFeedbackButton ( ) ;
397
+ } )
372
398
373
399
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
374
400
} ) ;
375
401
376
- it ( 'the Feedback Button matches the snapshot with default configuration and system dark theme' , ( ) => {
402
+ it ( 'the Feedback Button matches the snapshot with default configuration and system dark theme' , async ( ) => {
377
403
mockedIsModalSupported . mockReturnValue ( true ) ;
378
404
const { toJSON } = render (
379
405
< FeedbackWidgetProvider >
@@ -383,12 +409,14 @@ describe('FeedbackButtonManager', () => {
383
409
384
410
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
385
411
386
- showFeedbackButton ( ) ;
412
+ await act ( async ( ) => {
413
+ showFeedbackButton ( ) ;
414
+ } ) ;
387
415
388
416
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
389
417
} ) ;
390
418
391
- it ( 'the Feedback Button matches the snapshot with default configuration and dynamically changed theme' , ( ) => {
419
+ it ( 'the Feedback Button matches the snapshot with default configuration and dynamically changed theme' , async ( ) => {
392
420
const component = (
393
421
< FeedbackWidgetProvider >
394
422
< Text > App Components</ Text >
@@ -400,15 +428,19 @@ describe('FeedbackButtonManager', () => {
400
428
401
429
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
402
430
403
- showFeedbackButton ( ) ;
431
+ await act ( async ( ) => {
432
+ showFeedbackButton ( ) ;
433
+ } ) ;
404
434
405
435
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
406
- listener ( { colorScheme : 'dark' } ) ;
436
+ await act ( async ( ) => {
437
+ listener ( { colorScheme : 'dark' } ) ;
438
+ } ) ;
407
439
408
440
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
409
441
} ) ;
410
442
411
- it ( 'the Feedback Button matches the snapshot with custom light theme' , ( ) => {
443
+ it ( 'the Feedback Button matches the snapshot with custom light theme' , async ( ) => {
412
444
mockedIsModalSupported . mockReturnValue ( true ) ;
413
445
const { toJSON } = render (
414
446
< FeedbackWidgetProvider >
@@ -425,12 +457,14 @@ describe('FeedbackButtonManager', () => {
425
457
} ) ;
426
458
getClient ( ) ?. addIntegration ( integration ) ;
427
459
428
- showFeedbackButton ( ) ;
460
+ await act ( async ( ) => {
461
+ showFeedbackButton ( ) ;
462
+ } ) ;
429
463
430
464
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
431
465
} ) ;
432
466
433
- it ( 'the Feedback Button matches the snapshot with custom dark theme' , ( ) => {
467
+ it ( 'the Feedback Button matches the snapshot with custom dark theme' , async ( ) => {
434
468
mockedIsModalSupported . mockReturnValue ( true ) ;
435
469
const { toJSON } = render (
436
470
< FeedbackWidgetProvider >
@@ -447,12 +481,14 @@ describe('FeedbackButtonManager', () => {
447
481
} ) ;
448
482
getClient ( ) ?. addIntegration ( integration ) ;
449
483
450
- showFeedbackButton ( ) ;
484
+ await act ( async ( ) => {
485
+ showFeedbackButton ( ) ;
486
+ } ) ;
451
487
452
488
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
453
489
} ) ;
454
490
455
- it ( 'the Feedback Button matches the snapshot with system light custom theme' , ( ) => {
491
+ it ( 'the Feedback Button matches the snapshot with system light custom theme' , async ( ) => {
456
492
mockedIsModalSupported . mockReturnValue ( true ) ;
457
493
const { toJSON } = render (
458
494
< FeedbackWidgetProvider >
@@ -471,12 +507,14 @@ describe('FeedbackButtonManager', () => {
471
507
472
508
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
473
509
474
- showFeedbackButton ( ) ;
510
+ await act ( async ( ) => {
511
+ showFeedbackButton ( ) ;
512
+ } ) ;
475
513
476
514
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
477
515
} ) ;
478
516
479
- it ( 'the Feedback Button matches the snapshot with system dark custom theme' , ( ) => {
517
+ it ( 'the Feedback Button matches the snapshot with system dark custom theme' , async ( ) => {
480
518
mockedIsModalSupported . mockReturnValue ( true ) ;
481
519
const { toJSON } = render (
482
520
< FeedbackWidgetProvider >
@@ -495,7 +533,9 @@ describe('FeedbackButtonManager', () => {
495
533
496
534
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
497
535
498
- showFeedbackButton ( ) ;
536
+ await act ( async ( ) => {
537
+ showFeedbackButton ( ) ;
538
+ } ) ;
499
539
500
540
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
501
541
} ) ;
0 commit comments