-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated date dependencies, refactored * Deleted npm check updates * Fixed DateFilter tests
- Loading branch information
1 parent
bf887d8
commit 5bef3d8
Showing
4 changed files
with
49 additions
and
50 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
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 |
---|---|---|
@@ -1,52 +1,48 @@ | ||
import { vi } from 'vitest' | ||
import { fireEvent, screen, render } from '@testing-library/react' | ||
|
||
import DateFilter from '~/components/enhanced-table/date-filter/DateFilter' | ||
|
||
const props = { | ||
filter: { from: '', to: '' }, | ||
setFilter: vi.fn(), | ||
clearFilter: vi.fn(), | ||
} | ||
|
||
const dateMock = new Date('2023-01-01') | ||
describe('DateFilter Component', () => { | ||
const mockSetFilter = vi.fn() | ||
const mockClearFilter = vi.fn() | ||
const filter = { from: new Date(), to: new Date() } | ||
|
||
describe('DateFilter test', () => { | ||
beforeEach(() => { | ||
render( | ||
<DateFilter { ...props } /> | ||
mockSetFilter.mockClear() | ||
mockClearFilter.mockClear() | ||
}) | ||
|
||
it('renders calendar icon button', () => { | ||
render( | ||
<DateFilter | ||
clearFilter={mockClearFilter} | ||
filter={filter} | ||
setFilter={mockSetFilter} | ||
/> | ||
) | ||
expect(screen.getByTestId('calendar-icon')).toBeInTheDocument() | ||
}) | ||
|
||
it('Should open, and change value in calendar', () => { | ||
const calendarIcon = screen.getByTestId('calendar-icon') | ||
|
||
fireEvent.click(calendarIcon) | ||
|
||
const dateFilterBtn = screen.getAllByLabelText('Choose date') | ||
|
||
fireEvent.click(dateFilterBtn[0]) | ||
|
||
const dateFromInput = screen.getByLabelText('date-filter-from') | ||
|
||
fireEvent.change(dateFromInput, { target: { value: dateMock } }) | ||
|
||
fireEvent.keyDown(document, { key: 'Escape' }) | ||
|
||
expect(props.setFilter).toHaveBeenCalled() | ||
it('calls clearFilter when clear icon button is clicked', () => { | ||
render( | ||
<DateFilter | ||
clearFilter={mockClearFilter} | ||
filter={filter} | ||
setFilter={mockSetFilter} | ||
/> | ||
) | ||
fireEvent.click(screen.getByTestId('clear-icon')) | ||
expect(mockClearFilter).toHaveBeenCalled() | ||
}) | ||
|
||
it('Should clear value in calendar', async () => { | ||
|
||
const dateToInput = screen.getByLabelText('date-filter-to') | ||
|
||
fireEvent.change(dateToInput, { target: { value: dateMock } }) | ||
|
||
const clearIcon = screen.getByTestId('clear-icon') | ||
|
||
fireEvent.click(clearIcon) | ||
|
||
expect(props.clearFilter).toHaveBeenCalled() | ||
it('shows clear icon button when filter is not empty', () => { | ||
render( | ||
<DateFilter | ||
clearFilter={mockClearFilter} | ||
filter={filter} | ||
setFilter={mockSetFilter} | ||
/> | ||
) | ||
expect(screen.getByTestId('clear-icon')).toBeVisible() | ||
}) | ||
}) |