Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tests for filters component (#5632)
- Loading branch information
Showing
5 changed files
with
87 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { FILTER_ITEM } from 'utils/testIds'; | ||
import { Filters, IFilterItem } from './Filters'; | ||
|
||
test('shoulder render all available filters', async () => { | ||
const availableFilters: IFilterItem[] = [ | ||
{ | ||
label: 'Filter1', | ||
options: [], | ||
filterKey: 'irrelevantKey', | ||
singularOperators: ['IRRELEVANT'], | ||
pluralOperators: ['IRRELEVANT'], | ||
}, | ||
{ | ||
label: 'Filter2', | ||
options: [], | ||
filterKey: 'irrelevantKey', | ||
singularOperators: ['IRRELEVANT'], | ||
pluralOperators: ['IRRELEVANT'], | ||
}, | ||
{ | ||
label: 'Filter3', | ||
options: [], | ||
filterKey: 'irrelevantKey', | ||
singularOperators: ['IRRELEVANT'], | ||
pluralOperators: ['IRRELEVANT'], | ||
}, | ||
]; | ||
|
||
render( | ||
<Filters | ||
availableFilters={availableFilters} | ||
onChange={() => {}} | ||
state={{}} | ||
/>, | ||
); | ||
|
||
await screen.findByText('Filter1'); | ||
await screen.findByText('Filter2'); | ||
await screen.findByText('Filter3'); | ||
}); | ||
|
||
test('should keep filters order when adding a new filter', async () => { | ||
const availableFilters: IFilterItem[] = [ | ||
{ | ||
label: 'State', | ||
options: [], | ||
filterKey: 'irrelevantKey', | ||
singularOperators: ['IRRELEVANT'], | ||
pluralOperators: ['IRRELEVANT'], | ||
}, | ||
{ | ||
label: 'Tags', | ||
options: [], | ||
filterKey: 'irrelevantKey', | ||
singularOperators: ['IRRELEVANT'], | ||
pluralOperators: ['IRRELEVANT'], | ||
}, | ||
]; | ||
|
||
render( | ||
<Filters | ||
availableFilters={availableFilters} | ||
onChange={() => {}} | ||
state={{}} | ||
/>, | ||
); | ||
|
||
const valuesElement = await screen.findByText('Tags'); | ||
expect(valuesElement).toBeInTheDocument(); | ||
valuesElement.click(); | ||
|
||
const stateElement = await screen.findByText('State'); | ||
expect(stateElement).toBeInTheDocument(); | ||
|
||
stateElement.click(); | ||
|
||
const filterItems = screen.getAllByTestId(FILTER_ITEM); | ||
const filterTexts = filterItems.map((item) => item.textContent); | ||
|
||
expect(filterTexts).toEqual(['Tags', 'State']); | ||
}); |
4 changes: 2 additions & 2 deletions
4
frontend/src/component/filter/Filters.tsx → .../src/component/filter/Filters/Filters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters