1
1
import Api from '@api-platform/api-doc-parser/lib/Api' ;
2
2
import Field from '@api-platform/api-doc-parser/lib/Field' ;
3
3
import Resource from '@api-platform/api-doc-parser/lib/Resource' ;
4
- import { DisabledInput , TextInput } from 'react-admin' ;
4
+ import {
5
+ ArrayInput ,
6
+ DisabledInput ,
7
+ SimpleFormIterator ,
8
+ TextInput ,
9
+ } from 'react-admin' ;
5
10
import { shallow } from 'enzyme' ;
6
11
import React from 'react' ;
7
12
import Edit from './Edit' ;
@@ -36,6 +41,12 @@ const resourceData = {
36
41
required : true ,
37
42
deprecated : true ,
38
43
} ) ,
44
+ new Field ( 'fieldD' , {
45
+ id : 'http://schema.org/fieldD' ,
46
+ range : 'http://www.w3.org/2001/XMLSchema#array' ,
47
+ reference : null ,
48
+ required : true ,
49
+ } ) ,
39
50
] ,
40
51
} ;
41
52
@@ -67,10 +78,13 @@ describe('<Edit />', () => {
67
78
/> ,
68
79
) ;
69
80
70
- expect ( defaultInputFactory ) . toHaveBeenCalledTimes ( 2 ) ;
81
+ expect ( defaultInputFactory ) . toHaveBeenCalledTimes ( 3 ) ;
82
+ expect ( render . find ( ArrayInput ) . length ) . toEqual ( 1 ) ;
71
83
expect ( render . find ( DisabledInput ) . length ) . toEqual ( 1 ) ;
72
84
expect ( render . find ( DisabledInput ) . get ( 0 ) . props . source ) . toEqual ( 'id' ) ;
73
- expect ( render . find ( TextInput ) . length ) . toEqual ( 2 ) ;
85
+ expect ( render . find ( SimpleFormIterator ) . length ) . toEqual ( 1 ) ;
86
+ expect ( render . find ( TextInput ) . length ) . toEqual ( 3 ) ;
87
+ expect ( render . find ( ArrayInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldD' ) ;
74
88
expect ( render . find ( TextInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldA' ) ;
75
89
expect ( render . find ( TextInput ) . get ( 1 ) . props . source ) . toEqual ( 'fieldB' ) ;
76
90
} ) ;
@@ -103,9 +117,11 @@ describe('<Edit />', () => {
103
117
/> ,
104
118
) ;
105
119
106
- expect ( defaultInputFactory ) . toHaveBeenCalledTimes ( 2 ) ;
120
+ expect ( defaultInputFactory ) . toHaveBeenCalledTimes ( 3 ) ;
121
+ expect ( render . find ( ArrayInput ) . length ) . toEqual ( 1 ) ;
107
122
expect ( render . find ( DisabledInput ) . length ) . toEqual ( 0 ) ;
108
- expect ( render . find ( TextInput ) . length ) . toEqual ( 2 ) ;
123
+ expect ( render . find ( TextInput ) . length ) . toEqual ( 3 ) ;
124
+ expect ( render . find ( ArrayInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldD' ) ;
109
125
expect ( render . find ( TextInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldA' ) ;
110
126
expect ( render . find ( TextInput ) . get ( 1 ) . props . source ) . toEqual ( 'fieldB' ) ;
111
127
} ) ;
@@ -141,11 +157,14 @@ describe('<Edit />', () => {
141
157
/> ,
142
158
) ;
143
159
144
- expect ( customInputFactory ) . toHaveBeenCalledTimes ( 2 ) ;
160
+ expect ( customInputFactory ) . toHaveBeenCalledTimes ( 3 ) ;
145
161
expect ( defaultInputFactory ) . toHaveBeenCalledTimes ( 0 ) ;
162
+ expect ( render . find ( ArrayInput ) . length ) . toEqual ( 1 ) ;
146
163
expect ( render . find ( DisabledInput ) . length ) . toEqual ( 1 ) ;
147
164
expect ( render . find ( DisabledInput ) . get ( 0 ) . props . source ) . toEqual ( 'id' ) ;
148
- expect ( render . find ( TextInput ) . length ) . toEqual ( 2 ) ;
165
+ expect ( render . find ( SimpleFormIterator ) . length ) . toEqual ( 1 ) ;
166
+ expect ( render . find ( TextInput ) . length ) . toEqual ( 3 ) ;
167
+ expect ( render . find ( ArrayInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldD' ) ;
149
168
expect ( render . find ( TextInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldA' ) ;
150
169
expect ( render . find ( TextInput ) . get ( 1 ) . props . source ) . toEqual ( 'fieldB' ) ;
151
170
} ) ;
@@ -162,6 +181,12 @@ describe('<Edit />', () => {
162
181
reference : null ,
163
182
required : true ,
164
183
} ) ,
184
+ new Field ( 'fieldE' , {
185
+ id : 'http://schema.org/fieldE' ,
186
+ range : 'http://www.w3.org/2001/XMLSchema#array' ,
187
+ reference : null ,
188
+ required : true ,
189
+ } ) ,
165
190
] ,
166
191
} ) ;
167
192
@@ -183,10 +208,13 @@ describe('<Edit />', () => {
183
208
/> ,
184
209
) ;
185
210
186
- expect ( defaultInputFactory ) . toHaveBeenCalledTimes ( 1 ) ;
211
+ expect ( defaultInputFactory ) . toHaveBeenCalledTimes ( 2 ) ;
212
+ expect ( render . find ( ArrayInput ) . length ) . toEqual ( 1 ) ;
187
213
expect ( render . find ( DisabledInput ) . length ) . toEqual ( 1 ) ;
188
214
expect ( render . find ( DisabledInput ) . get ( 0 ) . props . source ) . toEqual ( 'id' ) ;
189
- expect ( render . find ( TextInput ) . length ) . toEqual ( 1 ) ;
215
+ expect ( render . find ( SimpleFormIterator ) . length ) . toEqual ( 1 ) ;
216
+ expect ( render . find ( TextInput ) . length ) . toEqual ( 2 ) ;
217
+ expect ( render . find ( ArrayInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldE' ) ;
190
218
expect ( render . find ( TextInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldC' ) ;
191
219
} ) ;
192
220
@@ -227,11 +255,14 @@ describe('<Edit />', () => {
227
255
/> ,
228
256
) ;
229
257
230
- expect ( defaultInputFactory ) . toHaveBeenCalledTimes ( 3 ) ;
258
+ expect ( defaultInputFactory ) . toHaveBeenCalledTimes ( 4 ) ;
259
+ expect ( render . find ( ArrayInput ) . length ) . toEqual ( 1 ) ;
231
260
expect ( render . find ( DisabledInput ) . length ) . toEqual ( 0 ) ;
232
- expect ( render . find ( TextInput ) . length ) . toEqual ( 3 ) ;
261
+ expect ( render . find ( TextInput ) . length ) . toEqual ( 4 ) ;
262
+ expect ( render . find ( ArrayInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldD' ) ;
233
263
expect ( render . find ( TextInput ) . get ( 0 ) . props . source ) . toEqual ( 'fieldA' ) ;
234
264
expect ( render . find ( TextInput ) . get ( 1 ) . props . source ) . toEqual ( 'fieldB' ) ;
235
- expect ( render . find ( TextInput ) . get ( 2 ) . props . source ) . toEqual ( 'id' ) ;
265
+ expect ( render . find ( TextInput ) . get ( 2 ) . props . source ) . toEqual ( undefined ) ;
266
+ expect ( render . find ( TextInput ) . get ( 3 ) . props . source ) . toEqual ( 'id' ) ;
236
267
} ) ;
237
268
} ) ;
0 commit comments