@@ -91,6 +91,16 @@ const settings = {
91
91
description : 'foo' ,
92
92
category : [ 'general' ] ,
93
93
} ,
94
+ {
95
+ ...defaults ,
96
+ name : 'general:test:array' ,
97
+ ariaName : 'array test' ,
98
+ displayName : 'Test array setting' ,
99
+ description : 'array foo' ,
100
+ type : 'array' as UiSettingsType ,
101
+ category : [ 'general' ] ,
102
+ defVal : [ 'test' ] ,
103
+ } ,
94
104
] ,
95
105
'x-pack' : [
96
106
{
@@ -256,4 +266,60 @@ describe('Form', () => {
256
266
} )
257
267
) ;
258
268
} ) ;
269
+
270
+ it ( 'should save an array typed field when user provides an empty string correctly' , async ( ) => {
271
+ const wrapper = mountWithI18nProvider (
272
+ < Form
273
+ settings = { settings }
274
+ visibleSettings = { settings }
275
+ categories = { categories }
276
+ categoryCounts = { categoryCounts }
277
+ save = { save }
278
+ clearQuery = { clearQuery }
279
+ showNoResultsMessage = { true }
280
+ enableSaving = { false }
281
+ toasts = { { } as any }
282
+ dockLinks = { { } as any }
283
+ />
284
+ ) ;
285
+
286
+ ( wrapper . instance ( ) as Form ) . setState ( {
287
+ unsavedChanges : {
288
+ 'general:test:array' : {
289
+ value : '' ,
290
+ } ,
291
+ } ,
292
+ } ) ;
293
+
294
+ findTestSubject ( wrapper . update ( ) , `advancedSetting-saveButton` ) . simulate ( 'click' ) ;
295
+ expect ( save ) . toHaveBeenCalledWith ( { 'general:test:array' : [ ] } ) ;
296
+ } ) ;
297
+
298
+ it ( 'should save an array typed field when user provides a comma separated string correctly' , async ( ) => {
299
+ const wrapper = mountWithI18nProvider (
300
+ < Form
301
+ settings = { settings }
302
+ visibleSettings = { settings }
303
+ categories = { categories }
304
+ categoryCounts = { categoryCounts }
305
+ save = { save }
306
+ clearQuery = { clearQuery }
307
+ showNoResultsMessage = { true }
308
+ enableSaving = { false }
309
+ toasts = { { } as any }
310
+ dockLinks = { { } as any }
311
+ />
312
+ ) ;
313
+
314
+ ( wrapper . instance ( ) as Form ) . setState ( {
315
+ unsavedChanges : {
316
+ 'general:test:array' : {
317
+ value : 'test1, test2' ,
318
+ } ,
319
+ } ,
320
+ } ) ;
321
+
322
+ findTestSubject ( wrapper . update ( ) , `advancedSetting-saveButton` ) . simulate ( 'click' ) ;
323
+ expect ( save ) . toHaveBeenCalledWith ( { 'general:test:array' : [ 'test1' , 'test2' ] } ) ;
324
+ } ) ;
259
325
} ) ;
0 commit comments