shlink-web-client/test/utils/DateInput.test.tsx

35 lines
1.4 KiB
TypeScript
Raw Normal View History

import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
2020-08-26 21:03:23 +03:00
import { Mock } from 'ts-mockery';
import { DateInput, DateInputProps } from '../../src/utils/DateInput';
2018-08-12 10:01:11 +03:00
describe('<DateInput />', () => {
const setUp = (props: Partial<DateInputProps> = {}) => ({
user: userEvent.setup(),
...render(<DateInput {...Mock.of<DateInputProps>(props)} />),
2018-08-12 10:01:11 +03:00
});
it('shows calendar icon when input is not clearable', () => {
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', () => {
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', () => {
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
});
});