2022-07-17 10:15:36 +03:00
|
|
|
import { screen } from '@testing-library/react';
|
2022-05-28 12:16:59 +03:00
|
|
|
import { DateRangeRow } from '../../../src/utils/dates/DateRangeRow';
|
2022-07-17 10:15:36 +03:00
|
|
|
import { renderWithEvents } from '../../__helpers__/setUpTest';
|
2020-01-14 22:20:27 +03:00
|
|
|
|
|
|
|
describe('<DateRangeRow />', () => {
|
2023-05-27 12:57:26 +03:00
|
|
|
const onEndDateChange = vi.fn();
|
|
|
|
const onStartDateChange = vi.fn();
|
2022-07-17 10:15:36 +03:00
|
|
|
const setUp = () => renderWithEvents(
|
|
|
|
<DateRangeRow onEndDateChange={onEndDateChange} onStartDateChange={onStartDateChange} />,
|
|
|
|
);
|
2020-01-14 22:20:27 +03:00
|
|
|
|
|
|
|
it('renders two date inputs', () => {
|
2022-07-17 10:15:36 +03:00
|
|
|
setUp();
|
|
|
|
expect(screen.getAllByRole('textbox')).toHaveLength(2);
|
2020-01-14 22:20:27 +03:00
|
|
|
});
|
|
|
|
|
2022-07-17 10:15:36 +03:00
|
|
|
it('invokes start date callback when change event is triggered on first input', async () => {
|
|
|
|
const { user } = setUp();
|
2020-01-14 22:20:27 +03:00
|
|
|
|
|
|
|
expect(onStartDateChange).not.toHaveBeenCalled();
|
2022-07-17 10:15:36 +03:00
|
|
|
await user.type(screen.getByPlaceholderText('Since...'), '2020-05-05');
|
2020-01-14 22:20:27 +03:00
|
|
|
expect(onStartDateChange).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2022-07-17 10:15:36 +03:00
|
|
|
it('invokes end date callback when change event is triggered on second input', async () => {
|
|
|
|
const { user } = setUp();
|
2020-01-14 22:20:27 +03:00
|
|
|
|
|
|
|
expect(onEndDateChange).not.toHaveBeenCalled();
|
2022-07-17 10:15:36 +03:00
|
|
|
await user.type(screen.getByPlaceholderText('Until...'), '2022-05-05');
|
2020-01-14 22:20:27 +03:00
|
|
|
expect(onEndDateChange).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|