Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Sep 29, 2020
1 parent 15c02ae commit 9b8b0a4
Show file tree
Hide file tree
Showing 2 changed files with 282 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ const settings = {
description: 'foo',
category: ['general'],
},
{
...defaults,
name: 'general:test:array',
ariaName: 'array test',
displayName: 'Test array setting',
description: 'array foo',
type: 'array' as UiSettingsType,
category: ['general'],
defVal: ['test'],
},
],
'x-pack': [
{
Expand Down Expand Up @@ -256,4 +266,60 @@ describe('Form', () => {
})
);
});

it('should save an array typed field when user provides an empty string correctly', async () => {
const wrapper = mountWithI18nProvider(
<Form
settings={settings}
visibleSettings={settings}
categories={categories}
categoryCounts={categoryCounts}
save={save}
clearQuery={clearQuery}
showNoResultsMessage={true}
enableSaving={false}
toasts={{} as any}
dockLinks={{} as any}
/>
);

(wrapper.instance() as Form).setState({
unsavedChanges: {
'general:test:array': {
value: '',
},
},
});

findTestSubject(wrapper.update(), `advancedSetting-saveButton`).simulate('click');
expect(save).toHaveBeenCalledWith({ 'general:test:array': [] });
});

it('should save an array typed field when user provides a comma separated string correctly', async () => {
const wrapper = mountWithI18nProvider(
<Form
settings={settings}
visibleSettings={settings}
categories={categories}
categoryCounts={categoryCounts}
save={save}
clearQuery={clearQuery}
showNoResultsMessage={true}
enableSaving={false}
toasts={{} as any}
dockLinks={{} as any}
/>
);

(wrapper.instance() as Form).setState({
unsavedChanges: {
'general:test:array': {
value: 'test1, test2',
},
},
});

findTestSubject(wrapper.update(), `advancedSetting-saveButton`).simulate('click');
expect(save).toHaveBeenCalledWith({ 'general:test:array': ['test1', 'test2'] });
});
});

0 comments on commit 9b8b0a4

Please sign in to comment.