Files
calendar/apps/web/modules/bookings/components/DatePicker.test.tsx
T
Benny JooGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
c7ee3984ef refactor: move feature-flags, calendars, and schedules components from packages/features to apps/web/modules (#27222)
* refactor: move feature-flags, calendars, and schedules components from packages/features to apps/web/modules

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* fix

* fix

* fix

* fix: move DatePicker and DateOverrideInputDialog to apps/web/modules and update imports

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* rename

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* wip

* wip

* wip

* fix unit tests

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-01-29 16:41:44 +02:00

120 lines
3.2 KiB
TypeScript

import React from "react";
import { vi, afterEach } from "vitest";
import dayjs from "@calcom/dayjs";
import { DatePicker as DatePickerComponent } from "@calcom/features/calendars/components/DatePicker";
import { render } from "@calcom/features/bookings/Booker/__tests__/test-utils";
import { DatePicker } from "./DatePicker";
vi.mock("@calcom/features/calendars/components/DatePicker", () => {
return {
DatePicker: vi.fn(() => <div data-testid="mock-date-picker" />),
};
});
const noop = () => {
/* noop */
};
describe("Tests for DatePicker Component", () => {
afterEach(() => {
vi.clearAllMocks();
});
test("It passes the loading prop to the DatePicker component", async () => {
render(<DatePicker event={{}} isLoading={true} />);
expect(DatePickerComponent).toHaveBeenCalledWith(
expect.objectContaining({
isLoading: true,
}),
expect.anything()
);
});
test("happy path, slots in current month", async () => {
// today current time.
const testDate = dayjs();
render(
<DatePicker
event={{}}
slots={{
[`${testDate.format("YYYY-MM-DD")}`]: [
{
time: testDate.format("YYYY-MM-DDTHH:mm:ss"),
},
],
}}
isLoading={false}
/>
);
// slot date is next month, so it'll have skipped the current month
// by setting the browsingDate to the next month.
expect(DatePickerComponent).toHaveBeenCalledWith(
expect.objectContaining({
browsingDate: dayjs().startOf("month"),
}),
expect.anything()
);
});
test("when there are only slots in the next month, skip the current month", async () => {
// there'll be one slot open on this day, next month.
const slotDate = dayjs().add(1, "month");
render(
<DatePicker
event={{}}
slots={{
[`${slotDate.format("YYYY-MM-DD")}`]: [
{
time: slotDate.format("YYYY-MM-DDTHH:mm:ss"),
},
],
}}
isLoading={false}
/>,
{
mockStore: {
month: slotDate.format("YYYY-MM"), // Start with next month to simulate the auto-advance
},
}
);
// slot date is next month, so it'll have skipped the current month
// by setting the browsingDate to the next month.
expect(DatePickerComponent).toHaveBeenCalledWith(
expect.objectContaining({
browsingDate: slotDate.startOf("month"),
}),
expect.anything()
);
});
test("when there are no slots, check for infinite loop (skip only 1 month)", async () => {
render(
<DatePicker
event={{}}
slots={
{
/* no slots given at all, but not loading */
}
}
isLoading={false}
/>,
{
mockStore: {
month: dayjs().add(1, "month").format("YYYY-MM"), // Start with next month to simulate the auto-advance
},
}
);
// slot date is next month, so it'll have skipped the current month
// by setting the browsingDate to the next month.
expect(DatePickerComponent).toHaveBeenCalledWith(
expect.objectContaining({
browsingDate: dayjs().add(1, "month").startOf("month"),
}),
expect.anything()
);
});
});