1
1
// Library
2
2
import React from 'react' ;
3
- import { shallow , mount } from 'enzyme' ;
3
+ import { mountTheme , shallowTheme } from '../../helpers/ enzyme-unit-test ' ;
4
4
5
5
// Material UI
6
- import { ThemeProvider , createTheme } from '@mui/material/styles' ;
7
6
import IconButton from '@mui/material/IconButton' ;
8
7
9
8
// Internal
@@ -28,21 +27,21 @@ describe('FieldSet', () => {
28
27
const data = { } ;
29
28
30
29
// act
31
- const wrapper = mount (
32
- < ThemeProvider theme = { createTheme ( ) } >
33
- < RawFieldSet
34
- classes = { { root } }
35
- schema = { schema }
36
- data = { data }
37
- path = { 'path' }
38
- uiSchema = { { } }
39
- xhrSchema = { { } }
40
- onKeyDown = { jest . fn }
41
- onChange = { jest . fn }
42
- onXHRSchemaEvent = { jest . fn }
43
- />
44
- </ ThemeProvider > ,
45
- ) ;
30
+ const wrapper = mountTheme ( {
31
+ component : (
32
+ < RawFieldSet
33
+ classes = { { root } }
34
+ schema = { schema }
35
+ data = { data }
36
+ path = { 'path' }
37
+ uiSchema = { { } }
38
+ xhrSchema = { { } }
39
+ onKeyDown = { jest . fn }
40
+ onChange = { jest . fn }
41
+ onXHRSchemaEvent = { jest . fn }
42
+ />
43
+ )
44
+ } ) ;
46
45
47
46
// check
48
47
expect ( wrapper ) . toHaveLength ( 1 ) ;
@@ -69,26 +68,26 @@ describe('FieldSet', () => {
69
68
const data = { name : 'Bob' } ;
70
69
71
70
// act
72
- const wrapper = mount (
73
- < ThemeProvider theme = { createTheme ( ) } >
71
+ const wrapper = mountTheme ( {
72
+ component : (
74
73
< RawFieldSetObject
75
- classes = { { row } }
76
- schema = { schema }
77
- data = { data }
78
- path = { '' }
79
- uiSchema = { { } }
80
- xhrSchema = { { } }
81
- onKeyDown = { jest . fn }
82
- onChange = { jest . fn }
83
- onXHRSchemaEvent = { jest . fn }
84
- id = { '1' }
85
- idxKey = { '1' }
86
- validation = { { } }
87
- isTabContent = { false }
88
- tabKey = { '' }
74
+ classes = { { row } }
75
+ schema = { schema }
76
+ data = { data }
77
+ path = { '' }
78
+ uiSchema = { { } }
79
+ xhrSchema = { { } }
80
+ onKeyDown = { jest . fn }
81
+ onChange = { jest . fn }
82
+ onXHRSchemaEvent = { jest . fn }
83
+ id = { '1' }
84
+ idxKey = { '1' }
85
+ validation = { { } }
86
+ isTabContent = { false }
87
+ tabKey = { '' }
89
88
/>
90
- </ ThemeProvider > ,
91
- ) ;
89
+ )
90
+ } ) ;
92
91
93
92
// check
94
93
expect ( wrapper ) . toHaveLength ( 1 ) ;
@@ -113,8 +112,8 @@ describe('FieldSet', () => {
113
112
const data = { name : 'Bob' } ;
114
113
115
114
// act
116
- const wrapper = mount (
117
- < ThemeProvider theme = { createTheme ( ) } >
115
+ const wrapper = mountTheme ( {
116
+ component : (
118
117
< RawFieldSetObject
119
118
classes = { { row } }
120
119
schema = { schema }
@@ -131,8 +130,8 @@ describe('FieldSet', () => {
131
130
isTabContent = { false }
132
131
tabKey = { '' }
133
132
/>
134
- </ ThemeProvider > ,
135
- ) ;
133
+ )
134
+ } ) ;
136
135
137
136
// check
138
137
expect ( wrapper ) . toHaveLength ( 1 ) ;
@@ -159,26 +158,28 @@ describe('FieldSet', () => {
159
158
const data = { name : 'Bob' } ;
160
159
161
160
// act
162
- const wrapper = shallow (
163
- < ThemeProvider theme = { createTheme ( ) } >
161
+ const parent = shallowTheme ( {
162
+ component : (
164
163
< RawFieldSetObject
165
- classes = { { row } }
166
- schema = { schema }
167
- data = { data }
168
- uiSchema = { uiSchema }
169
- path = { '' }
170
- xhrSchema = { { } }
171
- onKeyDown = { jest . fn }
172
- onChange = { jest . fn }
173
- onXHRSchemaEvent = { jest . fn }
174
- id = { '1' }
175
- idxKey = { '1' }
176
- validation = { { } }
177
- isTabContent = { false }
178
- tabKey = { '' }
164
+ classes = { { row } }
165
+ schema = { schema }
166
+ data = { data }
167
+ uiSchema = { uiSchema }
168
+ path = { '' }
169
+ xhrSchema = { { } }
170
+ onKeyDown = { jest . fn }
171
+ onChange = { jest . fn }
172
+ onXHRSchemaEvent = { jest . fn }
173
+ id = { '1' }
174
+ idxKey = { '1' }
175
+ validation = { { } }
176
+ isTabContent = { false }
177
+ tabKey = { '' }
179
178
/>
180
- </ ThemeProvider > ,
181
- ) ;
179
+ )
180
+ } ) ;
181
+
182
+ const wrapper = parent . find ( 'RawFieldSetObject' ) . dive ( ) ;
182
183
183
184
// check
184
185
expect ( wrapper ) . toHaveLength ( 1 ) ;
@@ -222,8 +223,8 @@ describe('FieldSet', () => {
222
223
const onAddItem = jest . fn ( ) ;
223
224
224
225
// act
225
- const wrapper = shallow (
226
- < ThemeProvider theme = { createTheme ( ) } >
226
+ const parent = shallowTheme ( {
227
+ component : (
227
228
< RawFieldSetArray
228
229
startIdx = { startIdx }
229
230
onAddItem = { onAddItem }
@@ -236,8 +237,10 @@ describe('FieldSet', () => {
236
237
schema = { schema }
237
238
data = { data }
238
239
/>
239
- </ ThemeProvider > ,
240
- ) ;
240
+ )
241
+ } ) ;
242
+
243
+ const wrapper = parent . find ( 'RawFieldSetArray' ) . dive ( ) ;
241
244
242
245
// check
243
246
expect ( wrapper ) . toHaveLength ( 1 ) ;
@@ -286,17 +289,19 @@ describe('FieldSet', () => {
286
289
const data = [ 'Bob' , false ] ;
287
290
288
291
// act
289
- const wrapper = shallow (
290
- < ThemeProvider theme = { createTheme ( ) } >
292
+ const parent = shallowTheme ( {
293
+ component : (
291
294
< RawFieldSetArray
292
295
uiSchema = { uiSchema }
293
296
path = { path }
294
297
classes = { { row } }
295
298
schema = { schema }
296
299
data = { data }
297
300
/>
298
- </ ThemeProvider > ,
299
- ) ;
301
+ )
302
+ } ) ;
303
+
304
+ const wrapper = parent . find ( 'RawFieldSetArray' ) . dive ( ) ;
300
305
301
306
// check
302
307
expect ( wrapper ) . toHaveLength ( 1 ) ;
@@ -346,8 +351,8 @@ describe('FieldSet', () => {
346
351
const data = [ 'Bob' , false , 'Harry' , 'Susan' ] ;
347
352
348
353
// act
349
- const wrapper = shallow (
350
- < ThemeProvider theme = { createTheme ( ) } >
354
+ const parent = shallowTheme ( {
355
+ component : (
351
356
< RawFieldSetArray
352
357
onMoveItemUp = { onMoveItemUp }
353
358
onMoveItemDown = { onMoveItemDown }
@@ -358,8 +363,10 @@ describe('FieldSet', () => {
358
363
schema = { schema }
359
364
data = { data }
360
365
/>
361
- </ ThemeProvider > ,
362
- ) ;
366
+ )
367
+ } ) ;
368
+
369
+ const wrapper = parent . find ( 'RawFieldSetArray' ) . dive ( ) ;
363
370
364
371
// check
365
372
expect ( wrapper ) . toHaveLength ( 1 ) ;
@@ -396,17 +403,22 @@ describe('FieldSet', () => {
396
403
const onDeleteItem = jest . fn ( ) ;
397
404
398
405
// act
399
- const wrapper = shallow (
400
- < RawReorderControls
401
- onMoveItemDown = { onMoveItemDown }
402
- onDeleteItem = { onDeleteItem }
403
- onMoveItemUp = { onMoveItemUp }
404
- classes = { { row } }
405
- first
406
- last = { false }
407
- canReorder
408
- /> ,
409
- ) ;
406
+ const parent = shallowTheme ( {
407
+ component : (
408
+ < RawReorderControls
409
+ onMoveItemDown = { onMoveItemDown }
410
+ onDeleteItem = { onDeleteItem }
411
+ onMoveItemUp = { onMoveItemUp }
412
+ classes = { { row } }
413
+ first
414
+ last = { false }
415
+ canReorder
416
+ />
417
+ )
418
+ } ) ;
419
+
420
+ const wrapper = parent . find ( 'RawReorderControls' ) . dive ( ) ;
421
+
410
422
// check
411
423
expect ( wrapper ) . toHaveLength ( 1 ) ;
412
424
const buttonList = wrapper . find ( IconButton ) ;
@@ -420,9 +432,18 @@ describe('FieldSet', () => {
420
432
} ) ;
421
433
it ( 'ReorderControls - first' , ( ) => {
422
434
// act
423
- const wrapper = shallow (
424
- < RawReorderControls first last = { false } classes = { { row } } canReorder /> ,
425
- ) ;
435
+ const parent = shallowTheme ( {
436
+ component : (
437
+ < RawReorderControls
438
+ first
439
+ last = { false }
440
+ classes = { { row } }
441
+ canReorder
442
+ />
443
+ )
444
+ } ) ;
445
+
446
+ const wrapper = parent . find ( 'RawReorderControls' ) . dive ( ) ;
426
447
427
448
// check
428
449
expect ( wrapper ) . toHaveLength ( 1 ) ;
@@ -434,9 +455,18 @@ describe('FieldSet', () => {
434
455
} ) ;
435
456
it ( 'ReorderControls - last' , ( ) => {
436
457
// act
437
- const wrapper = shallow (
438
- < RawReorderControls first = { false } last classes = { { row } } canReorder /> ,
439
- ) ;
458
+ const parent = shallowTheme ( {
459
+ component : (
460
+ < RawReorderControls
461
+ first = { false }
462
+ last
463
+ classes = { { row } }
464
+ canReorder
465
+ />
466
+ )
467
+ } ) ;
468
+
469
+ const wrapper = parent . find ( 'RawReorderControls' ) . dive ( ) ;
440
470
441
471
// check
442
472
expect ( wrapper ) . toHaveLength ( 1 ) ;
@@ -454,14 +484,18 @@ describe('FieldSet', () => {
454
484
const first = true ;
455
485
const last = false ;
456
486
// act
457
- const wrapper = shallow (
458
- < RawReorderableFormField
459
- path = { path }
460
- first = { first }
461
- last = { last }
462
- classes = { { row } }
463
- /> ,
464
- ) ;
487
+ const parent = shallowTheme ( {
488
+ component : (
489
+ < RawReorderableFormField
490
+ path = { path }
491
+ first = { first }
492
+ last = { last }
493
+ classes = { { row } }
494
+ />
495
+ )
496
+ } ) ;
497
+
498
+ const wrapper = parent . find ( 'RawReorderableFormField' ) . dive ( ) ;
465
499
466
500
// check
467
501
const ffComp = wrapper . find ( FormField ) ;
0 commit comments