2022-07-10 00:03:21 +03:00
|
|
|
import { screen, waitFor } from '@testing-library/react';
|
2020-08-26 21:03:23 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2022-05-28 12:16:59 +03:00
|
|
|
import { DateInput, DateInputProps } from '../../src/utils/DateInput';
|
2022-07-10 20:44:49 +03:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2018-08-12 10:01:11 +03:00
|
|
|
|
|
|
|
describe('<DateInput />', () => {
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = (props: Partial<DateInputProps> = {}) => renderWithEvents(
|
|
|
|
<DateInput {...Mock.of<DateInputProps>(props)} />,
|
|
|
|
);
|
2018-08-12 10:01:11 +03:00
|
|
|
|
|
|
|
it('shows calendar icon when input is not clearable', () => {
|
2022-06-10 21:48:53 +03:00
|
|
|
setUp({ isClearable: false });
|
|
|
|
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
|
2018-08-12 10:01:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows calendar icon when input is clearable but selected value is nil', () => {
|
2022-06-10 21:48:53 +03:00
|
|
|
setUp({ isClearable: true, selected: null });
|
|
|
|
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
|
2018-08-12 10:01:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show calendar icon when input is clearable', () => {
|
2022-06-10 21:48:53 +03:00
|
|
|
setUp({ isClearable: true, selected: new Date() });
|
|
|
|
expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows popper on element click', async () => {
|
|
|
|
const { user, container } = setUp({ placeholderText: 'foo' });
|
|
|
|
|
|
|
|
expect(container.querySelector('.react-datepicker')).not.toBeInTheDocument();
|
|
|
|
await user.click(screen.getByPlaceholderText('foo'));
|
|
|
|
await waitFor(() => expect(container.querySelector('.react-datepicker')).toBeInTheDocument());
|
2018-08-12 10:01:11 +03:00
|
|
|
});
|
|
|
|
});
|