calcom/test/lib/slots.test.ts
Omar López 85d7122e43
Fixes Apple Calendar onboarding and type fixes (#988)
* Type fixes

* Type fixes

* Attemp to prevent unknown error in prod

* Type fixes

* Type fixes for onboarding

* Extracts ConnectIntegration

* Extracts IntegrationListItem

* Extracts CalendarsList

* Uses CalendarList on onboarding

* Removes deprecated Alert

* Extracts DisconnectIntegration

* Extracts CalendarSwitch

* Extracts ConnectedCalendarsList

* Extracted connectedCalendar logic for reuse

* Extracted SubHeadingTitleWithConnections

* Type fixes

* Fetched connected calendars in onboarding

* Refreshes data on when adding/removing calendars on onboarding

* Removed testing code

* Type fixes

* Feedback

* Moved integration helpers

* I was sleepy

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-10-20 15:42:40 +00:00

58 lines
1.7 KiB
TypeScript

import { expect, it } from "@jest/globals";
import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import MockDate from "mockdate";
import getSlots from "@lib/slots";
dayjs.extend(utc);
dayjs.extend(timezone);
MockDate.set("2021-06-20T11:59:59Z");
it("can fit 24 hourly slots for an empty day", async () => {
// 24h in a day.
expect(
getSlots({
inviteeDate: dayjs().add(1, "day"),
frequency: 60,
workingHours: [{ days: Array.from(Array(7).keys()), startTime: 0, endTime: 1440 }],
organizerTimeZone: "Europe/London",
})
).toHaveLength(24);
});
it.skip("only shows future booking slots on the same day", async () => {
// The mock date is 1s to midday, so 12 slots should be open given 0 booking notice.
expect(
getSlots({
inviteeDate: dayjs(),
frequency: 60,
workingHours: [{ days: Array.from(Array(7).keys()), startTime: 0, endTime: 1440 }],
organizerTimeZone: "GMT",
})
).toHaveLength(12);
});
it("can cut off dates that due to invitee timezone differences fall on the next day", async () => {
expect(
getSlots({
inviteeDate: dayjs().tz("Europe/Amsterdam").startOf("day"), // time translation +01:00
frequency: 60,
workingHours: [{ days: [0], startTime: 1380, endTime: 1440 }],
organizerTimeZone: "Europe/London",
})
).toHaveLength(0);
});
it.skip("can cut off dates that due to invitee timezone differences fall on the previous day", async () => {
expect(
getSlots({
inviteeDate: dayjs().startOf("day"), // time translation -01:00
frequency: 60,
workingHours: [{ days: [0], startTime: 0, endTime: 60 }],
organizerTimeZone: "Europe/London",
})
).toHaveLength(0);
});