Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to TypeScript #339

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/DateTimeInput.spec.jsx → src/DateTimeInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('DateTimeInput', () => {
className: 'react-datetime-picker__inputGroup',
};

let user;
let user: ReturnType<typeof userEvent.setup>;
beforeEach(() => {
user = userEvent.setup({
advanceTimers: vi.advanceTimersByTime.bind(vi),
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('DateTimeInput', () => {
const { container } = render(<DateTimeInput {...defaultProps} />);

const customInputs = container.querySelectorAll('input[data-input]');
const monthInput = customInputs[0];
const monthInput = customInputs[0] as HTMLInputElement;
const dayInput = customInputs[1];

await user.type(monthInput, '{arrowright}');
Expand All @@ -506,14 +506,14 @@ describe('DateTimeInput', () => {
const { container } = render(<DateTimeInput {...defaultProps} />);

const customInputs = container.querySelectorAll('input[data-input]');
const monthInput = customInputs[0];
const monthInput = customInputs[0] as HTMLInputElement;
const dayInput = customInputs[1];

const separators = container.querySelectorAll('.react-datetime-picker__inputGroup__divider');
const separatorsTexts = Array.from(separators)
.map((el) => el.textContent)
.map((el) => el.textContent as string)
.filter((el) => el.trim());
const separatorKey = separatorsTexts[0];
const separatorKey = separatorsTexts[0] as string;

await user.type(monthInput, separatorKey);

Expand All @@ -524,14 +524,14 @@ describe('DateTimeInput', () => {
const { container } = render(<DateTimeInput {...defaultProps} />);

const customInputs = container.querySelectorAll('input[data-input]');
const monthInput = customInputs[0];
const monthInput = customInputs[0] as HTMLInputElement;
const dayInput = customInputs[1];

const separators = container.querySelectorAll('.react-datetime-picker__inputGroup__divider');
const separatorsTexts = Array.from(separators)
.map((el) => el.textContent)
.map((el) => el.textContent as string)
.filter((el) => el.trim());
const separatorKey = separatorsTexts[separatorsTexts.length - 1];
const separatorKey = separatorsTexts[separatorsTexts.length - 1] as string;

await user.type(monthInput, separatorKey);

Expand All @@ -541,7 +541,7 @@ describe('DateTimeInput', () => {
it('does not jump to the next field when right arrow is pressed when the last input is focused', async () => {
const { container } = render(<DateTimeInput {...defaultProps} />);

const select = container.querySelector('select');
const select = container.querySelector('select') as HTMLSelectElement;

await user.type(select, '{arrowright}');

Expand All @@ -553,7 +553,7 @@ describe('DateTimeInput', () => {

const customInputs = container.querySelectorAll('input[data-input]');
const monthInput = customInputs[0];
const dayInput = customInputs[1];
const dayInput = customInputs[1] as HTMLInputElement;

await user.type(dayInput, '{arrowleft}');

Expand All @@ -564,7 +564,7 @@ describe('DateTimeInput', () => {
const { container } = render(<DateTimeInput {...defaultProps} />);

const customInputs = container.querySelectorAll('input[data-input]');
const monthInput = customInputs[0];
const monthInput = customInputs[0] as HTMLInputElement;

await user.type(monthInput, '{arrowleft}');

Expand All @@ -575,7 +575,7 @@ describe('DateTimeInput', () => {
const { container } = render(<DateTimeInput {...defaultProps} />);

const customInputs = container.querySelectorAll('input[data-input]');
const monthInput = customInputs[0];
const monthInput = customInputs[0] as HTMLInputElement;
const dayInput = customInputs[1];

await user.type(monthInput, '4');
Expand All @@ -587,7 +587,7 @@ describe('DateTimeInput', () => {
const { container } = render(<DateTimeInput {...defaultProps} />);

const customInputs = container.querySelectorAll('input[data-input]');
const monthInput = customInputs[0];
const monthInput = customInputs[0] as HTMLInputElement;
const dayInput = customInputs[1];

await user.type(monthInput, '03');
Expand All @@ -599,7 +599,7 @@ describe('DateTimeInput', () => {
const { container } = render(<DateTimeInput {...defaultProps} />);

const customInputs = container.querySelectorAll('input[data-input]');
const monthInput = customInputs[0];
const monthInput = customInputs[0] as HTMLInputElement;

await user.type(monthInput, '1');

Expand All @@ -615,7 +615,7 @@ describe('DateTimeInput', () => {
);

const customInputs = container.querySelectorAll('input[data-input]');
const hourInput = customInputs[3];
const hourInput = customInputs[3] as HTMLInputElement;

fireEvent.change(hourInput, { target: { value: '8' } });

Expand All @@ -634,7 +634,7 @@ describe('DateTimeInput', () => {
);

const customInputs = container.querySelectorAll('input[data-input]');
const hourInput = customInputs[3];
const hourInput = customInputs[3] as HTMLInputElement;

fireEvent.change(hourInput, { target: { value: '8' } });

Expand All @@ -655,7 +655,7 @@ describe('DateTimeInput', () => {
);

const customInputs = container.querySelectorAll('input[data-input]');
const hourInput = customInputs[2];
const hourInput = customInputs[2] as HTMLInputElement;

fireEvent.change(hourInput, { target: { value: '20' } });

Expand Down Expand Up @@ -691,7 +691,7 @@ describe('DateTimeInput', () => {
<DateTimeInput {...defaultProps} onChange={onChange} value={date} />,
);

const nativeInput = container.querySelector('input[type="datetime-local"]');
const nativeInput = container.querySelector('input[type="datetime-local"]') as HTMLInputElement;

fireEvent.change(nativeInput, { target: { value: '2017-09-30T20:17:00' } });

Expand All @@ -709,7 +709,7 @@ describe('DateTimeInput', () => {
<DateTimeInput {...defaultProps} onChange={onChange} value={date} />,
);

const nativeInput = container.querySelector('input[type="datetime-local"]');
const nativeInput = container.querySelector('input[type="datetime-local"]') as HTMLInputElement;

fireEvent.change(nativeInput, { target: { value: '0019-09-20T20:17:00' } });

Expand All @@ -729,7 +729,7 @@ describe('DateTimeInput', () => {
<DateTimeInput {...defaultProps} onChange={onChange} value={date} />,
);

const nativeInput = container.querySelector('input[type="datetime-local"]');
const nativeInput = container.querySelector('input[type="datetime-local"]') as HTMLInputElement;

fireEvent.change(nativeInput, { target: { value: '' } });

Expand Down
Loading