@@ -102,31 +102,7 @@ describe("useBulkAction", () => {
102
102
expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
103
103
} ) ;
104
104
105
- test ( "can execute a bulk create with params" , async ( ) => {
106
- const mockBulkCreate = {
107
- type : "action" ,
108
- operationName : "bulkCreateWidgets" ,
109
- namespace : null ,
110
- modelApiIdentifier : "widget" ,
111
- modelSelectionField : "widgets" ,
112
- isBulk : true ,
113
- defaultSelection : {
114
- id : true ,
115
- name : true ,
116
- } ,
117
- selectionType : { } ,
118
- optionsType : { } ,
119
- schemaType : null ,
120
- variablesType : void 0 ,
121
- variables : {
122
- inputs : {
123
- required : true ,
124
- type : "[BulkCreateWidgetsInput!]" ,
125
- } ,
126
- } ,
127
- hasReturnType : false ,
128
- } as any ;
129
-
105
+ test ( "can execute a bulk create with flattened params" , async ( ) => {
130
106
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
131
107
// @ts -ignore waiting for bulk params to be released gadget side
132
108
const { result } = renderHook ( ( ) => useBulkAction < any , any , any , any > ( mockBulkCreate ) , { wrapper : MockClientWrapper ( bulkExampleApi ) } ) ;
@@ -141,18 +117,20 @@ describe("useBulkAction", () => {
141
117
expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
142
118
143
119
expect ( mockUrqlClient . executeMutation ) . toBeCalledTimes ( 1 ) ;
144
- expect ( mockUrqlClient . executeMutation . mock . calls [ 0 ] [ 0 ] . variables ) . toMatchInlineSnapshot ( `
145
- {
146
- "inputs": [
147
- {
148
- " name" : "foo",
120
+ expect ( mockUrqlClient . executeMutation . mock . calls [ 0 ] [ 0 ] . variables ) . toEqual ( {
121
+ inputs : [
122
+ {
123
+ widget : {
124
+ name : "foo" ,
149
125
} ,
150
- {
151
- "name": "bar",
126
+ } ,
127
+ {
128
+ widget : {
129
+ name : "bar" ,
152
130
} ,
153
- ] ,
154
- }
155
- ` ) ;
131
+ } ,
132
+ ] ,
133
+ } ) ;
156
134
157
135
mockUrqlClient . executeMutation . pushResponse ( "bulkCreateWidgets" , {
158
136
data : {
@@ -183,30 +161,6 @@ describe("useBulkAction", () => {
183
161
} ) ;
184
162
185
163
test ( "can execute a bulk create with fully qualified params" , async ( ) => {
186
- const mockBulkCreate = {
187
- type : "action" ,
188
- operationName : "bulkCreateWidgets" ,
189
- namespace : null ,
190
- modelApiIdentifier : "widget" ,
191
- modelSelectionField : "widgets" ,
192
- isBulk : true ,
193
- defaultSelection : {
194
- id : true ,
195
- name : true ,
196
- } ,
197
- selectionType : { } ,
198
- optionsType : { } ,
199
- schemaType : null ,
200
- variablesType : void 0 ,
201
- variables : {
202
- inputs : {
203
- required : true ,
204
- type : "[BulkCreateWidgetsInput!]" ,
205
- } ,
206
- } ,
207
- hasReturnType : false ,
208
- } as any ;
209
-
210
164
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
211
165
// @ts -ignore waiting for bulk params to be released gadget side
212
166
const { result } = renderHook ( ( ) => useBulkAction < any , any , any , any > ( mockBulkCreate ) , { wrapper : MockClientWrapper ( bulkExampleApi ) } ) ;
@@ -221,22 +175,20 @@ describe("useBulkAction", () => {
221
175
expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
222
176
223
177
expect ( mockUrqlClient . executeMutation ) . toBeCalledTimes ( 1 ) ;
224
- expect ( mockUrqlClient . executeMutation . mock . calls [ 0 ] [ 0 ] . variables ) . toMatchInlineSnapshot ( `
225
- {
226
- "inputs": [
227
- {
228
- "widget": {
229
- "name": "foo",
230
- },
178
+ expect ( mockUrqlClient . executeMutation . mock . calls [ 0 ] [ 0 ] . variables ) . toEqual ( {
179
+ inputs : [
180
+ {
181
+ widget : {
182
+ name : "foo" ,
231
183
} ,
232
- {
233
- "widget": {
234
- "name": "bar",
235
- } ,
184
+ } ,
185
+ {
186
+ widget : {
187
+ name : "bar" ,
236
188
} ,
237
- ] ,
238
- }
239
- ` ) ;
189
+ } ,
190
+ ] ,
191
+ } ) ;
240
192
241
193
mockUrqlClient . executeMutation . pushResponse ( "bulkCreateWidgets" , {
242
194
data : {
@@ -266,40 +218,79 @@ describe("useBulkAction", () => {
266
218
expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
267
219
} ) ;
268
220
269
- test ( "can execute a bulk update with params" , async ( ) => {
270
- const mockBulkUpdate = {
271
- type : "action" ,
272
- operationName : "bulkUpdateWidgets" ,
273
- namespace : null ,
274
- modelApiIdentifier : "widget" ,
275
- modelSelectionField : "widgets" ,
276
- isBulk : true ,
277
- defaultSelection : {
278
- id : true ,
279
- name : true ,
280
- } ,
281
- selectionType : { } ,
282
- optionsType : { } ,
283
- schemaType : null ,
284
- variablesType : void 0 ,
285
- variables : {
286
- inputs : {
287
- required : true ,
288
- type : "[BulkUpdateWidgetsInput!]" ,
221
+ test ( "can execute a bulk update with flattened params" , async ( ) => {
222
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
223
+ // @ts -ignore waiting for bulk params to be released gadget side
224
+ const { result } = renderHook ( ( ) => useBulkAction < any , any , any , any > ( mockBulkUpdate ) , { wrapper : MockClientWrapper ( bulkExampleApi ) } ) ;
225
+
226
+ let mutationPromise : any ;
227
+ act ( ( ) => {
228
+ mutationPromise = result . current [ 1 ] ( [
229
+ { id : "123" , name : "foo" } ,
230
+ { id : "124" , name : "bar" } ,
231
+ ] ) ;
232
+ } ) ;
233
+
234
+ expect ( result . current [ 0 ] . data ) . toBeFalsy ( ) ;
235
+ expect ( result . current [ 0 ] . fetching ) . toBe ( true ) ;
236
+ expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
237
+
238
+ expect ( mockUrqlClient . executeMutation ) . toBeCalledTimes ( 1 ) ;
239
+ expect ( mockUrqlClient . executeMutation . mock . calls [ 0 ] [ 0 ] . variables ) . toEqual ( {
240
+ inputs : [
241
+ {
242
+ id : "123" ,
243
+ widget : {
244
+ name : "foo" ,
245
+ } ,
246
+ } ,
247
+ {
248
+ id : "124" ,
249
+ widget : {
250
+ name : "bar" ,
251
+ } ,
252
+ } ,
253
+ ] ,
254
+ } ) ;
255
+
256
+ mockUrqlClient . executeMutation . pushResponse ( "bulkUpdateWidgets" , {
257
+ data : {
258
+ bulkUpdateWidgets : {
259
+ success : true ,
260
+ widgets : [
261
+ { id : "123" , name : "foo" } ,
262
+ { id : "124" , name : "bar" } ,
263
+ ] ,
289
264
} ,
290
265
} ,
291
- hasReturnType : false ,
292
- } as any ;
266
+ stale : false ,
267
+ hasNext : false ,
268
+ } ) ;
293
269
270
+ await act ( async ( ) => {
271
+ const promiseResult = await mutationPromise ;
272
+ expect ( promiseResult . data ! . length ) . toEqual ( 2 ) ;
273
+ expect ( promiseResult . data ! [ 0 ] . id ) . toEqual ( "123" ) ;
274
+ expect ( promiseResult . data ! [ 1 ] . id ) . toEqual ( "124" ) ;
275
+ } ) ;
276
+
277
+ expect ( result . current [ 0 ] . data ! . length ) . toEqual ( 2 ) ;
278
+ expect ( result . current [ 0 ] . data ! [ 0 ] . id ) . toEqual ( "123" ) ;
279
+ expect ( result . current [ 0 ] . data ! [ 1 ] . id ) . toEqual ( "124" ) ;
280
+ expect ( result . current [ 0 ] . fetching ) . toBe ( false ) ;
281
+ expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
282
+ } ) ;
283
+
284
+ test ( "can execute a bulk update with fully qualified params" , async ( ) => {
294
285
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
295
286
// @ts -ignore waiting for bulk params to be released gadget side
296
287
const { result } = renderHook ( ( ) => useBulkAction < any , any , any , any > ( mockBulkUpdate ) , { wrapper : MockClientWrapper ( bulkExampleApi ) } ) ;
297
288
298
289
let mutationPromise : any ;
299
290
act ( ( ) => {
300
291
mutationPromise = result . current [ 1 ] ( [
301
- { id : "123" , name : "foo" } ,
302
- { id : "124" , name : "bar" } ,
292
+ { id : "123" , widget : { name : "foo" } } ,
293
+ { id : "124" , widget : { name : "bar" } } ,
303
294
] ) ;
304
295
} ) ;
305
296
@@ -308,20 +299,22 @@ describe("useBulkAction", () => {
308
299
expect ( result . current [ 0 ] . error ) . toBeFalsy ( ) ;
309
300
310
301
expect ( mockUrqlClient . executeMutation ) . toBeCalledTimes ( 1 ) ;
311
- expect ( mockUrqlClient . executeMutation . mock . calls [ 0 ] [ 0 ] . variables ) . toMatchInlineSnapshot ( `
312
- {
313
- "inputs": [
314
- {
315
- "id": "123",
316
- " name" : "foo",
302
+ expect ( mockUrqlClient . executeMutation . mock . calls [ 0 ] [ 0 ] . variables ) . toEqual ( {
303
+ inputs : [
304
+ {
305
+ id : "123" ,
306
+ widget : {
307
+ name : "foo" ,
317
308
} ,
318
- {
319
- "id": "124",
320
- "name": "bar",
309
+ } ,
310
+ {
311
+ id : "124" ,
312
+ widget : {
313
+ name : "bar" ,
321
314
} ,
322
- ] ,
323
- }
324
- ` ) ;
315
+ } ,
316
+ ] ,
317
+ } ) ;
325
318
326
319
mockUrqlClient . executeMutation . pushResponse ( "bulkUpdateWidgets" , {
327
320
data : {
@@ -440,3 +433,53 @@ describe("useBulkAction", () => {
440
433
expect ( result . current [ 0 ] ) . toBe ( beforeObject ) ;
441
434
} ) ;
442
435
} ) ;
436
+
437
+ const mockBulkCreate = {
438
+ type : "action" ,
439
+ operationName : "bulkCreateWidgets" ,
440
+ namespace : null ,
441
+ modelApiIdentifier : "widget" ,
442
+ modelSelectionField : "widgets" ,
443
+ isBulk : true ,
444
+ defaultSelection : {
445
+ id : true ,
446
+ name : true ,
447
+ } ,
448
+ selectionType : { } ,
449
+ optionsType : { } ,
450
+ schemaType : null ,
451
+ variablesType : void 0 ,
452
+ variables : {
453
+ inputs : {
454
+ required : true ,
455
+ type : "[BulkCreateWidgetsInput!]" ,
456
+ } ,
457
+ } ,
458
+ acceptsModelInput : true ,
459
+ hasReturnType : false ,
460
+ } as any ;
461
+
462
+ const mockBulkUpdate = {
463
+ type : "action" ,
464
+ operationName : "bulkUpdateWidgets" ,
465
+ namespace : null ,
466
+ modelApiIdentifier : "widget" ,
467
+ modelSelectionField : "widgets" ,
468
+ isBulk : true ,
469
+ defaultSelection : {
470
+ id : true ,
471
+ name : true ,
472
+ } ,
473
+ selectionType : { } ,
474
+ optionsType : { } ,
475
+ schemaType : null ,
476
+ variablesType : void 0 ,
477
+ variables : {
478
+ inputs : {
479
+ required : true ,
480
+ type : "[BulkUpdateWidgetsInput!]" ,
481
+ } ,
482
+ } ,
483
+ acceptsModelInput : true ,
484
+ hasReturnType : false ,
485
+ } as any ;
0 commit comments