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

tests: added interaction tests for DatePickerInput #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { ComponentMeta, ComponentStory } from '@storybook/react';
import { within, userEvent } from '@storybook/testing-library';
import { expect } from '@storybook/jest';

import { delay } from '../../common';
import { ControlledExample } from './DatePickerInput';

export default {
Expand Down Expand Up @@ -37,3 +40,64 @@ Default.parameters = {
},
},
};

export const Interactions = Default.bind({});

Interactions.args = {
...Default.args,
testID: 'datepickerInputInteractions',
};

Interactions.parameters = {
...Default.parameters,
};

Interactions.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);

await delay(500);

// first clear the input
await userEvent.clear(canvas.getByTestId('datepickerInputInteractions-flat'));

await delay(500);

// type in the wrong format
await userEvent.type(canvas.getByTestId('datepickerInputInteractions-flat'), '1311');

await delay(500);

await userEvent.type(canvas.getByTestId('datepickerInputInteractions-flat'), '111');

await delay(500);

// should show an error
await expect(canvas.getByText('Date format must be MM/dd/yy')).toBeInTheDocument();

await delay(500);

// clear again
await userEvent.clear(canvas.getByTestId('datepickerInputInteractions-flat'));

await delay(500);

// type in the correct format
await userEvent.type(canvas.getByTestId('datepickerInputInteractions-flat'), '121122');

await delay(500);

// the error should be gone
await expect(canvas.queryByText('Date format must be MM/dd/yy')).not.toBeTruthy();

await delay(500);

// click the calendar icon
await userEvent.click(canvas.getByRole('button'));

await delay(500);

// the modal should show up
await expect(
within(canvasElement.ownerDocument.body).getByText('SELECT DATE'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should be the expected selected date in the picker? Checking for Select Date is okay.
Checking for the selected date value is even better!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a separate date picker related test, I want to see what happens when you click on the edit icon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On changing the date, a test should validate that the date in the picker is also correct.

).toBeInTheDocument();
};