initial implementation of search in UI_next

This commit is contained in:
John Mitchell
2019-07-23 15:39:30 -04:00
parent 602ee856fa
commit a58468ffee
37 changed files with 3166 additions and 2008 deletions

View File

@@ -12,15 +12,19 @@ describe('<Search />', () => {
});
test('it triggers the expected callbacks', () => {
const columns = [{ name: 'Name', key: 'name', isSortable: true }];
const columns = [{ name: 'Name', key: 'name', isSortable: true, isSearchable: true }];
const searchBtn = 'button[aria-label="Search"]';
const searchBtn = 'button[aria-label="Search submit button"]';
const searchTextInput = 'input[aria-label="Search text input"]';
const onSearch = jest.fn();
search = mountWithContexts(
<Search sortedColumnKey="name" columns={columns} onSearch={onSearch} />
<Search
sortedColumnKey="name"
columns={columns}
onSearch={onSearch}
/>
);
search.find(searchTextInput).instance().value = 'test-321';
@@ -28,14 +32,18 @@ describe('<Search />', () => {
search.find(searchBtn).simulate('click');
expect(onSearch).toHaveBeenCalledTimes(1);
expect(onSearch).toBeCalledWith('test-321');
expect(onSearch).toBeCalledWith('name__icontains', 'test-321');
});
test('handleDropdownToggle properly updates state', async () => {
const columns = [{ name: 'Name', key: 'name', isSortable: true }];
const columns = [{ name: 'Name', key: 'name', isSortable: true, isSearchable: true }];
const onSearch = jest.fn();
const wrapper = mountWithContexts(
<Search sortedColumnKey="name" columns={columns} onSearch={onSearch} />
<Search
sortedColumnKey="name"
columns={columns}
onSearch={onSearch}
/>
).find('Search');
expect(wrapper.state('isSearchDropdownOpen')).toEqual(false);
wrapper.instance().handleDropdownToggle(true);
@@ -44,17 +52,19 @@ describe('<Search />', () => {
test('handleDropdownSelect properly updates state', async () => {
const columns = [
{ name: 'Name', key: 'name', isSortable: true },
{ name: 'Description', key: 'description', isSortable: true },
{ name: 'Name', key: 'name', isSortable: true, isSearchable: true },
{ name: 'Description', key: 'description', isSortable: true, isSearchable: true }
];
const onSearch = jest.fn();
const wrapper = mountWithContexts(
<Search sortedColumnKey="name" columns={columns} onSearch={onSearch} />
<Search
sortedColumnKey="name"
columns={columns}
onSearch={onSearch}
/>
).find('Search');
expect(wrapper.state('searchKey')).toEqual('name');
wrapper
.instance()
.handleDropdownSelect({ target: { innerText: 'Description' } });
wrapper.instance().handleDropdownSelect({ target: { innerText: 'Description' } });
expect(wrapper.state('searchKey')).toEqual('description');
});
});