Added test covering custom formatting in DateInput

This commit is contained in:
Alejandro Celaya
2022-10-23 10:43:01 +02:00
parent 10d3deff37
commit c3b60367f3
6 changed files with 30 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import { screen, waitFor } from '@testing-library/react';
import { Mock } from 'ts-mockery';
import { parseISO } from 'date-fns';
import { DateInput, DateInputProps } from '../../src/utils/DateInput';
import { renderWithEvents } from '../__helpers__/setUpTest';
@@ -30,4 +31,14 @@ describe('<DateInput />', () => {
await user.click(screen.getByPlaceholderText('foo'));
await waitFor(() => expect(container.querySelector('.react-datepicker')).toBeInTheDocument());
});
it.each([
[undefined, '2022-01-01'],
['yyyy-MM-dd', '2022-01-01'],
['yyyy-MM-dd HH:mm', '2022-01-01 15:18'],
['HH:mm:ss', '15:18:36'],
])('shows date in expected format', (dateFormat, expectedValue) => {
setUp({ placeholderText: 'foo', selected: parseISO('2022-01-01T15:18:36'), dateFormat });
expect(screen.getByPlaceholderText('foo')).toHaveValue(expectedValue);
});
});