Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
25 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
frontend/src/component/common/FilterDateItem/FilterDateItem.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { vi } from 'vitest'; | ||
import { FilterItemParams } from '../FilterItem/FilterItem'; | ||
import { FilterDateItem, IFilterDateItemProps } from './FilterDateItem'; | ||
|
||
const getDate = (option: string) => screen.getByText(option); | ||
|
||
const setup = (initialState: FilterItemParams) => { | ||
const recordedChanges: FilterItemParams[] = []; | ||
const mockProps: IFilterDateItemProps = { | ||
label: 'Test Label', | ||
onChange: (value: FilterItemParams) => { | ||
recordedChanges.push(value); | ||
}, | ||
onChipClose: () => {}, | ||
operators: ['IS_ON_OR_AFTER', 'IS_BEFORE'], | ||
state: initialState, | ||
}; | ||
|
||
render(<FilterDateItem {...mockProps} />); | ||
|
||
return recordedChanges; | ||
}; | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
describe('FilterDateItem Component', () => { | ||
it('renders initial state correctly', async () => { | ||
const mockState = { | ||
operator: 'IS_ON_OR_AFTER', | ||
values: ['2015-01-21'], | ||
}; | ||
|
||
const recordedChanges = setup(mockState); | ||
|
||
const valuesElement = await screen.findByText('01/21/2015'); | ||
await screen.findByText('is on or after'); | ||
expect(valuesElement).toBeInTheDocument(); | ||
|
||
valuesElement.click(); | ||
|
||
const selectedDate = getDate('21'); | ||
|
||
expect(selectedDate).toHaveAttribute('aria-selected', 'true'); | ||
|
||
getDate('22').click(); | ||
|
||
expect(recordedChanges).toEqual([ | ||
{ | ||
operator: 'IS_ON_OR_AFTER', | ||
values: ['2015-01-22'], | ||
}, | ||
]); | ||
}); | ||
|
||
it('switches operator', async () => { | ||
const mockState = { | ||
operator: 'IS_ON_OR_AFTER', | ||
values: ['2020-01-01'], | ||
}; | ||
|
||
const recordedChanges = setup(mockState); | ||
|
||
const operatorsElement = await screen.findByText('is on or after'); | ||
|
||
operatorsElement.click(); | ||
const newOperator = await screen.findByText('is before'); | ||
|
||
newOperator.click(); | ||
|
||
expect(recordedChanges).toEqual([ | ||
{ | ||
operator: 'IS_BEFORE', | ||
values: ['2020-01-01'], | ||
}, | ||
]); | ||
}); | ||
}); |
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
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