Skip to content

Commit

Permalink
fix(interaction-tests): passing storybook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bejoinka committed Oct 16, 2024
1 parent 691e713 commit 4c48d68
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 54 deletions.
18 changes: 9 additions & 9 deletions src/atoms/Calendar/week/WeekCalendar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export const NoAvailabilitiesSpec = async ({
name: 'Telehealth'
});
await userEvent.click(virtualButton);
const mondayCard = await canvas.findByTestId('Mon Jan 01 2024');
const tuesdayCard = await canvas.findByTestId('Tue Jan 02 2024');
const wednesdayCard = await canvas.findByTestId('Wed Jan 03 2024');
const thursdayCard = await canvas.findByTestId('Thu Jan 04 2024');
const fridayCard = await canvas.findByTestId('Fri Jan 05 2024');
const mondayCard = await canvas.findByTestId('Mon Oct 14 2024');
const tuesdayCard = await canvas.findByTestId('Tue Oct 15 2024');
const wednesdayCard = await canvas.findByTestId('Wed Oct 16 2024');
const thursdayCard = await canvas.findByTestId('Thu Oct 17 2024');
const fridayCard = await canvas.findByTestId('Fri Oct 18 2024');
for (const card of [
mondayCard,
tuesdayCard,
Expand All @@ -32,8 +32,8 @@ export const NoAvailabilitiesSpec = async ({

await userEvent.click(prevWeekButton);
expect(
await canvas.findByTestId('Mon Dec 25 2023'),
'Dec 25 2023 should be visible'
await canvas.findByTestId('Mon Oct 07 2024'),
'Oct 7 2024 should be visible'
).toBeVisible();
await expect(
prevWeekButton,
Expand All @@ -43,8 +43,8 @@ export const NoAvailabilitiesSpec = async ({
// back at jan 1
await userEvent.click(nextWeekButton);
expect(
await canvas.findByTestId('Mon Jan 08 2024'),
'Jan 08 2024 should be visible'
await canvas.findByTestId('Mon Oct 21 2024'),
'Oct 21 2024 should be visible'
).toBeVisible();
await userEvent.click(nextWeekButton);
await userEvent.click(nextWeekButton);
Expand Down
2 changes: 1 addition & 1 deletion src/atoms/Calendar/week/WeekCalendar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const meta: Meta<typeof WeekCalendarComponent> = {
title: 'Atoms/Calendar/Week',
component: WeekCalendarComponent,
parameters: {
mockingDate: new Date('2024-09-01T18:00:00.000Z')
mockingDate: new Date('2024-10-14T18:00:00.000Z')
},
args: { onDateSelect: fn(), onLocationSelect: fn() },
decorators: [
Expand Down
6 changes: 5 additions & 1 deletion src/lib/api/schema/atoms/TherapeuticModality.schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isEmpty } from 'lodash-es';
import { z } from 'zod';

export enum Modality {
Expand All @@ -9,10 +10,13 @@ export enum Modality {

export const TherapeuticModalitySchema = z
.nativeEnum(Modality)
.optional()
.transform((value) => {
if (value === Modality.Therapy) {
return 'Therapy';
} else {
} else if (!isEmpty(value)) {
return 'Psychiatric';
} else {
return undefined;
}
});
77 changes: 34 additions & 43 deletions src/molecules/Scheduler/Scheduler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ export const SchedulerSpec = async ({
const canvas = within(canvasElement);

/** Get all elements of interests */
const cherryCreekButton = await canvas.findByRole('button', {
name: 'Cherry Creek'
});
const unionSquareButton = await canvas.findByRole('button', {
name: 'Union Square'
const brooklynHeightsButton = await canvas.findByRole('button', {
name: 'NY - Brooklyn Heights'
});
const virtualButton = await canvas.findByRole('button', {
name: 'Telehealth'
Expand All @@ -28,63 +25,57 @@ export const SchedulerSpec = async ({

// Calendar navigation
await userEvent.click(prevWeekButton);
const prevWeekDayCard = await canvas.findByTestId('Mon Dec 25 2023');
const prevWeekDayCard = await canvas.findByTestId('Mon Oct 07 2024');
expect(prevWeekDayCard, 'prev week should be visible').toBeVisible();
await userEvent.click(nextWeekButton);

// Default state (Virtual)
const mondayCard = await canvas.findByTestId('Mon Jan 01 2024');
const tuesdayCard = await canvas.findByTestId('Tue Jan 02 2024');

expect(
await within(mondayCard).findByText('2 slots'),
'monday should have 2 slots'
).toBeTruthy();
const thursdayCard = await canvas.findByTestId('Thu Oct 17 2024');
expect(thursdayCard, 'thursday card should be visible').toBeVisible();
expect(
await within(tuesdayCard).findByText('3 slots'),
'tuesday should have three slots'
await within(thursdayCard).findByText('1 slot'),
'Thursday should have 1 slot'
).toBeTruthy();

// Cherry Creek
await userEvent.click(cherryCreekButton);
await userEvent.click(nextWeekButton);
const nextMondayCard = await canvas.findByTestId('Mon Oct 21 2024');
expect(nextMondayCard, 'next monday card should be visible').toBeVisible();

expect(
await within(mondayCard).findByText('1 slot'),
'monday should have 1 slot'
).toBeTruthy();
expect(
await within(tuesdayCard).findByText('1 slot'),
'tuesday should have 1 slot'
await within(nextMondayCard).findByText('2 slots'),
'monday the 21st should have two slots'
).toBeTruthy();

// Union Square
await userEvent.click(unionSquareButton);
expect(
await within(mondayCard).findByText('No slots'),
'monday should have no slots'
).toBeTruthy();
// In-person
await userEvent.click(brooklynHeightsButton);

expect(
await within(tuesdayCard).findByText('1 slot'),
'tuesday should have 1 slot'
await within(nextMondayCard).findByText('1 slot'),
'monday should have 1 slot'
).toBeTruthy();

// Go back to virtual and let's test the slots
// Virtual
await userEvent.click(virtualButton);
await userEvent.click(mondayCard);
const slotsContainer = await canvas.findByTestId('slots');
await expect(slotsContainer.children.length).toBe(2); // Monday has 2 slots
await userEvent.click(tuesdayCard);
await expect(slotsContainer.children.length).toBe(3); // Tuesday has 3 slots

const elevenAmSlot = (await slotsContainer.querySelector(
'[aria-label="2024-01-02T10:00:00.000Z"]'

await userEvent.click(nextMondayCard);
const nextWeekSlotsContainer = await canvas.findByTestId('slots');
await expect(nextWeekSlotsContainer.children.length).toBe(2); // Monday has 2 slots
await userEvent.click(prevWeekButton);

const thursdayCard2 = await canvas.findByTestId('Thu Oct 17 2024');
await userEvent.click(thursdayCard2);
const thisWeekSlotsContainer = await canvas.findByTestId('slots');
await expect(thisWeekSlotsContainer.children.length).toBe(1); // Thursday has 1 slot

const slotToBook = (await thisWeekSlotsContainer.querySelector(
'[aria-label="2024-10-17T21:00:00.000Z"]'
)) as HTMLElement;

if (elevenAmSlot === null) {
throw new Error('No 10 AM (UTC) slot found');
if (slotToBook === null) {
throw new Error('No 9 PM (UTC) slot found');
}

await userEvent.click(elevenAmSlot);
await userEvent.click(slotToBook);

const bookButton = await canvas.findByRole('button', {
name: 'Confirm booking'
Expand Down

0 comments on commit 4c48d68

Please sign in to comment.