@@ -202,4 +202,86 @@ describe('<ReferenceArrayFieldController />', () => {
202
202
expect ( dispatch . mock . calls [ 0 ] [ 0 ] . type ) . toBe ( 'RA/CRUD_GET_MANY' ) ;
203
203
expect ( dataProvider . getMany ) . toBeCalledTimes ( 1 ) ;
204
204
} ) ;
205
+
206
+ it ( 'should filter string data based on the filter props' , ( ) => {
207
+ const children = jest . fn ( ) . mockReturnValue ( 'child' ) ;
208
+ renderWithRedux (
209
+ < ReferenceArrayFieldController
210
+ record = { { id : 1 , barIds : [ 1 , 2 ] } }
211
+ filter = { { title : 'world' } }
212
+ resource = "foo"
213
+ reference = "bar"
214
+ source = "barIds"
215
+ basePath = ""
216
+ >
217
+ { children }
218
+ </ ReferenceArrayFieldController > ,
219
+ {
220
+ admin : {
221
+ resources : {
222
+ bar : {
223
+ data : {
224
+ 1 : { id : 1 , title : 'hello' } ,
225
+ 2 : { id : 2 , title : 'world' } ,
226
+ } ,
227
+ } ,
228
+ } ,
229
+ } ,
230
+ }
231
+ ) ;
232
+ expect ( children . mock . calls [ 0 ] [ 0 ] ) . toMatchObject ( {
233
+ basePath : '' ,
234
+ currentSort : { field : 'id' , order : 'ASC' } ,
235
+ loaded : true ,
236
+ loading : true ,
237
+ data : {
238
+ 2 : { id : 2 , title : 'world' } ,
239
+ } ,
240
+ ids : [ 1 , 2 ] ,
241
+ error : null ,
242
+ } ) ;
243
+ } ) ;
244
+
245
+ it ( 'should filter array data based on the filter props' , ( ) => {
246
+ const children = jest . fn ( ) . mockReturnValue ( 'child' ) ;
247
+ renderWithRedux (
248
+ < ReferenceArrayFieldController
249
+ record = { { id : 1 , barIds : [ 1 , 2 , 3 , 4 ] } }
250
+ filter = { { items : [ 'two' , 'four' , 'five' ] } }
251
+ resource = "foo"
252
+ reference = "bar"
253
+ source = "barIds"
254
+ basePath = ""
255
+ >
256
+ { children }
257
+ </ ReferenceArrayFieldController > ,
258
+ {
259
+ admin : {
260
+ resources : {
261
+ bar : {
262
+ data : {
263
+ 1 : { id : 1 , items : [ 'one' , 'two' ] } ,
264
+ 2 : { id : 2 , items : [ 'three' ] } ,
265
+ 3 : { id : 3 , items : 'four' } ,
266
+ 4 : { id : 4 , items : [ 'five' ] } ,
267
+ } ,
268
+ } ,
269
+ } ,
270
+ } ,
271
+ }
272
+ ) ;
273
+ expect ( children . mock . calls [ 0 ] [ 0 ] ) . toMatchObject ( {
274
+ basePath : '' ,
275
+ currentSort : { field : 'id' , order : 'ASC' } ,
276
+ loaded : true ,
277
+ loading : true ,
278
+ data : {
279
+ 1 : { id : 1 , items : [ 'one' , 'two' ] } ,
280
+ 3 : { id : 3 , items : 'four' } ,
281
+ 4 : { id : 4 , items : [ 'five' ] } ,
282
+ } ,
283
+ ids : [ 1 , 2 , 3 , 4 ] ,
284
+ error : null ,
285
+ } ) ;
286
+ } ) ;
205
287
} ) ;
0 commit comments