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,17 @@ 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
278
listener ( { colorScheme : 'dark' } ) ;
265
279
266
280
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
267
281
} ) ;
268
282
269
- it ( 'the Feedback Widget matches the snapshot with custom light theme' , ( ) => {
283
+ it ( 'the Feedback Widget matches the snapshot with custom light theme' , async ( ) => {
270
284
mockedIsModalSupported . mockReturnValue ( true ) ;
271
285
const { toJSON } = render (
272
286
< FeedbackWidgetProvider >
@@ -283,12 +297,14 @@ describe('FeedbackButtonManager', () => {
283
297
} ) ;
284
298
getClient ( ) ?. addIntegration ( integration ) ;
285
299
286
- showFeedbackWidget ( ) ;
300
+ await act ( async ( ) => {
301
+ showFeedbackWidget ( ) ;
302
+ } ) ;
287
303
288
304
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
289
305
} ) ;
290
306
291
- it ( 'the Feedback Widget matches the snapshot with custom dark theme' , ( ) => {
307
+ it ( 'the Feedback Widget matches the snapshot with custom dark theme' , async ( ) => {
292
308
mockedIsModalSupported . mockReturnValue ( true ) ;
293
309
const { toJSON } = render (
294
310
< FeedbackWidgetProvider >
@@ -305,12 +321,14 @@ describe('FeedbackButtonManager', () => {
305
321
} ) ;
306
322
getClient ( ) ?. addIntegration ( integration ) ;
307
323
308
- showFeedbackWidget ( ) ;
324
+ await act ( async ( ) => {
325
+ showFeedbackWidget ( ) ;
326
+ } ) ;
309
327
310
328
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
311
329
} ) ;
312
330
313
- it ( 'the Feedback Widget matches the snapshot with system light custom theme' , ( ) => {
331
+ it ( 'the Feedback Widget matches the snapshot with system light custom theme' , async ( ) => {
314
332
mockedIsModalSupported . mockReturnValue ( true ) ;
315
333
const { toJSON } = render (
316
334
< FeedbackWidgetProvider >
@@ -329,12 +347,14 @@ describe('FeedbackButtonManager', () => {
329
347
330
348
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
331
349
332
- showFeedbackWidget ( ) ;
350
+ await act ( async ( ) => {
351
+ showFeedbackWidget ( ) ;
352
+ } ) ;
333
353
334
354
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
335
355
} ) ;
336
356
337
- it ( 'the Feedback Widget matches the snapshot with system dark custom theme' , ( ) => {
357
+ it ( 'the Feedback Widget matches the snapshot with system dark custom theme' , async ( ) => {
338
358
mockedIsModalSupported . mockReturnValue ( true ) ;
339
359
const { toJSON } = render (
340
360
< FeedbackWidgetProvider >
@@ -353,12 +373,14 @@ describe('FeedbackButtonManager', () => {
353
373
354
374
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
355
375
356
- showFeedbackWidget ( ) ;
376
+ await act ( async ( ) => {
377
+ showFeedbackWidget ( ) ;
378
+ } ) ;
357
379
358
380
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
359
381
} ) ;
360
382
361
- it ( 'the Feedback Button matches the snapshot with default configuration and system light theme' , ( ) => {
383
+ it ( 'the Feedback Button matches the snapshot with default configuration and system light theme' , async ( ) => {
362
384
mockedIsModalSupported . mockReturnValue ( true ) ;
363
385
const { toJSON } = render (
364
386
< FeedbackWidgetProvider >
@@ -368,12 +390,14 @@ describe('FeedbackButtonManager', () => {
368
390
369
391
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
370
392
371
- showFeedbackButton ( ) ;
393
+ await act ( async ( ) => {
394
+ showFeedbackWidget ( ) ;
395
+ } ) ;
372
396
373
397
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
374
398
} ) ;
375
399
376
- it ( 'the Feedback Button matches the snapshot with default configuration and system dark theme' , ( ) => {
400
+ it ( 'the Feedback Button matches the snapshot with default configuration and system dark theme' , async ( ) => {
377
401
mockedIsModalSupported . mockReturnValue ( true ) ;
378
402
const { toJSON } = render (
379
403
< FeedbackWidgetProvider >
@@ -383,12 +407,14 @@ describe('FeedbackButtonManager', () => {
383
407
384
408
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
385
409
386
- showFeedbackButton ( ) ;
410
+ await act ( async ( ) => {
411
+ showFeedbackWidget ( ) ;
412
+ } ) ;
387
413
388
414
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
389
415
} ) ;
390
416
391
- it ( 'the Feedback Button matches the snapshot with default configuration and dynamically changed theme' , ( ) => {
417
+ it ( 'the Feedback Button matches the snapshot with default configuration and dynamically changed theme' , async ( ) => {
392
418
const component = (
393
419
< FeedbackWidgetProvider >
394
420
< Text > App Components</ Text >
@@ -400,15 +426,17 @@ describe('FeedbackButtonManager', () => {
400
426
401
427
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
402
428
403
- showFeedbackButton ( ) ;
429
+ await act ( async ( ) => {
430
+ showFeedbackWidget ( ) ;
431
+ } ) ;
404
432
405
433
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
406
434
listener ( { colorScheme : 'dark' } ) ;
407
435
408
436
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
409
437
} ) ;
410
438
411
- it ( 'the Feedback Button matches the snapshot with custom light theme' , ( ) => {
439
+ it ( 'the Feedback Button matches the snapshot with custom light theme' , async ( ) => {
412
440
mockedIsModalSupported . mockReturnValue ( true ) ;
413
441
const { toJSON } = render (
414
442
< FeedbackWidgetProvider >
@@ -425,12 +453,14 @@ describe('FeedbackButtonManager', () => {
425
453
} ) ;
426
454
getClient ( ) ?. addIntegration ( integration ) ;
427
455
428
- showFeedbackButton ( ) ;
456
+ await act ( async ( ) => {
457
+ showFeedbackWidget ( ) ;
458
+ } ) ;
429
459
430
460
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
431
461
} ) ;
432
462
433
- it ( 'the Feedback Button matches the snapshot with custom dark theme' , ( ) => {
463
+ it ( 'the Feedback Button matches the snapshot with custom dark theme' , async ( ) => {
434
464
mockedIsModalSupported . mockReturnValue ( true ) ;
435
465
const { toJSON } = render (
436
466
< FeedbackWidgetProvider >
@@ -447,12 +477,14 @@ describe('FeedbackButtonManager', () => {
447
477
} ) ;
448
478
getClient ( ) ?. addIntegration ( integration ) ;
449
479
450
- showFeedbackButton ( ) ;
480
+ await act ( async ( ) => {
481
+ showFeedbackWidget ( ) ;
482
+ } ) ;
451
483
452
484
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
453
485
} ) ;
454
486
455
- it ( 'the Feedback Button matches the snapshot with system light custom theme' , ( ) => {
487
+ it ( 'the Feedback Button matches the snapshot with system light custom theme' , async ( ) => {
456
488
mockedIsModalSupported . mockReturnValue ( true ) ;
457
489
const { toJSON } = render (
458
490
< FeedbackWidgetProvider >
@@ -471,12 +503,14 @@ describe('FeedbackButtonManager', () => {
471
503
472
504
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'light' ) ;
473
505
474
- showFeedbackButton ( ) ;
506
+ await act ( async ( ) => {
507
+ showFeedbackWidget ( ) ;
508
+ } ) ;
475
509
476
510
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
477
511
} ) ;
478
512
479
- it ( 'the Feedback Button matches the snapshot with system dark custom theme' , ( ) => {
513
+ it ( 'the Feedback Button matches the snapshot with system dark custom theme' , async ( ) => {
480
514
mockedIsModalSupported . mockReturnValue ( true ) ;
481
515
const { toJSON } = render (
482
516
< FeedbackWidgetProvider >
@@ -495,7 +529,9 @@ describe('FeedbackButtonManager', () => {
495
529
496
530
jest . spyOn ( Appearance , 'getColorScheme' ) . mockReturnValue ( 'dark' ) ;
497
531
498
- showFeedbackButton ( ) ;
532
+ await act ( async ( ) => {
533
+ showFeedbackWidget ( ) ;
534
+ } ) ;
499
535
500
536
expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
501
537
} ) ;
0 commit comments