Skip to content

Commit

Permalink
fixup! 💄(frontend) replace to cunningham Datepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoLC committed Jul 19, 2023
1 parent 0025936 commit 83b5577
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ describe('<Scheduling />', () => {
),
);

await userTypeDatePicker(startingAt, userEvent);
await userTypeDatePicker(
startingAt,
screen.getByText(/Starting date/i),
userEvent,
);

deferredPatch.resolve({ message: 'Classroom scheduled.' });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('<SchedulingFields />', () => {
const startingAt = DateTime.local()
.plus({ days: 1 })
.set({ second: 0, millisecond: 0 });
await userTypeDatePicker(startingAt);
await userTypeDatePicker(startingAt, screen.getByText(/Starting date/i));
expect(inputStartingAtDate).toHaveTextContent(startingAt.toLocaleString());

const inputStartingAtTime = screen.getByLabelText(/starting time/i);
Expand Down Expand Up @@ -145,7 +145,10 @@ describe('<SchedulingFields />', () => {
screen.getByTestId('starting-at-date-picker'),
).getByRole('presentation');
expect(inputStartingAtDate).toHaveTextContent('mm/dd/yyyy');
await userTypeDatePicker(startingAtPast);
await userTypeDatePicker(
startingAtPast,
screen.getByText(/Starting date/i),
);
const allSpin = await screen.findAllByRole('spinbutton');

allSpin.forEach((spin) => {
Expand Down
11 changes: 6 additions & 5 deletions src/frontend/packages/lib_tests/src/cunningham.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ import { DateTime } from 'luxon';
* @param userEvent
*/
export const userTypeDatePicker = async (
startingAt: DateTime,
datetime: DateTime,
element: Element,
userEvent?: ReturnType<typeof userEventInit.setup>,
) => {
const localUserEvent = userEvent || userEventInit;
await localUserEvent.click(screen.getByText(/Starting date/i));
await localUserEvent.click(element);

const [monthSegment, daySegment, yearSegment] = await screen.findAllByRole(
'spinbutton',
);

await localUserEvent.click(monthSegment);
expect(monthSegment).toHaveFocus();
await localUserEvent.keyboard(startingAt.toFormat('MM'));
await localUserEvent.keyboard(datetime.toFormat('MM'));

expect(daySegment).toHaveFocus();
await localUserEvent.keyboard(startingAt.toFormat('dd'));
await localUserEvent.keyboard(datetime.toFormat('dd'));

expect(yearSegment).toHaveFocus();
await localUserEvent.keyboard(startingAt.toFormat('yyyy'));
await localUserEvent.keyboard(datetime.toFormat('yyyy'));
};
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ describe('<SchedulingAndDescription />', () => {

screen.getByText('Your live is not scheduled');

await userTypeDatePicker(startingAt, userEvent);
await userTypeDatePicker(
startingAt,
screen.getByText(/Starting date/i),
userEvent,
);

const inputStartingAtDate = within(
screen.getByTestId('starting-at-date-picker'),
Expand Down Expand Up @@ -224,7 +228,11 @@ describe('<SchedulingAndDescription />', () => {
),
);

await userTypeDatePicker(startingAt, userEvent);
await userTypeDatePicker(
startingAt,
screen.getByText(/Starting date/i),
userEvent,
);

expect(fetchMock.calls()).toHaveLength(0);

Expand Down

0 comments on commit 83b5577

Please sign in to comment.