add onShowAdvancedSearch callback test

This commit is contained in:
John Mitchell 2020-08-11 16:10:05 -04:00 committed by John Mitchell
parent a352de3da7
commit 1323626d5e

View File

@ -93,6 +93,52 @@ describe('<Search />', () => {
expect(onSearch).toBeCalledWith('description__icontains', 'test-321');
});
test('changing key select to and from advanced causes onShowAdvancedSearch callback to be invoked', () => {
const searchButton = 'button[aria-label="Search submit button"]';
const searchTextInput = 'input[aria-label="Search text input"]';
const columns = [
{ name: 'Name', key: 'name__icontains', isDefault: true },
{ name: 'Description', key: 'description__icontains' },
{ name: 'Advanced', key: 'advanced' },
];
const onSearch = jest.fn();
const onShowAdvancedSearch = jest.fn();
const wrapper = mountWithContexts(
<Toolbar
id={`${QS_CONFIG.namespace}-list-toolbar`}
clearAllFilters={() => {}}
collapseListedFiltersBreakpoint="lg"
>
<ToolbarContent>
<Search
qsConfig={QS_CONFIG}
columns={columns}
onSearch={onSearch}
onShowAdvancedSearch={onShowAdvancedSearch}
/>
</ToolbarContent>
</Toolbar>
);
act(() => {
wrapper
.find('Select[aria-label="Simple key select"]')
.invoke('onSelect')({ target: { innerText: 'Advanced' } });
});
wrapper.update();
expect(onShowAdvancedSearch).toHaveBeenCalledTimes(1);
expect(onShowAdvancedSearch).toBeCalledWith(true);
jest.clearAllMocks();
act(() => {
wrapper
.find('Select[aria-label="Simple key select"]')
.invoke('onSelect')({ target: { innerText: 'Description' } });
});
wrapper.update();
expect(onShowAdvancedSearch).toHaveBeenCalledTimes(1);
expect(onShowAdvancedSearch).toBeCalledWith(false);
});
test('attempt to search with empty string', () => {
const searchButton = 'button[aria-label="Search submit button"]';
const searchTextInput = 'input[aria-label="Search text input"]';