mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* fix manage test error * fix manage test error * update useBookerContext * wrap store provider around booker * replace useStore with useBookerStoreContext * replace useBookerStore with useBookerStoreContext * add initializer function for booker store provider * update props * fixup: pass more props * export StoreInitializeType type * replace useBookerStore with useBookerStoreContext * fixup: dont wrap BookerStoreProvider around booker directly * wrap BookerStoreProvider around booker web wrapper and fix local storage import * fix: wrap test components with BookerStoreProvider to fix failing unit tests - Create reusable test utility in test-utils.tsx with comprehensive mock store - Update Booker.test.tsx to use context-based testing approach - Fix DatePicker tests in both bookings and calendars packages - Simulate auto-advance behavior for month navigation tests - All 14 previously failing tests now pass Co-Authored-By: [email protected] <[email protected]> * add changesets * fix: complete migration from useBookerStore to useBookerStoreContext - Updated all remaining files to use useBookerStoreContext instead of useBookerStore - Fixed BookingFields.test.tsx by wrapping test component with BookerStoreProvider - Ensures all Booker components work within the new context-based store pattern - Resolves failing unit tests in CI by completing the store migration Co-Authored-By: [email protected] <[email protected]> * fix: add missing useBookerStoreContext import in BookerWebWrapper.tsx - Fixes TypeScript errors in CI where useBookerStoreContext was used but not imported - Completes the migration from useBookerStore to useBookerStoreContext pattern - All tests pass locally after this fix Co-Authored-By: [email protected] <[email protected]> * Revert "fix: add missing useBookerStoreContext import in BookerWebWrapper.tsx" This reverts commit 12947ca63f46c42e5aee74c78176ef230e2bf2cf. * Revert "fix: complete migration from useBookerStore to useBookerStoreContext" This reverts commit 87d837f2d30e4f9259d2be786049d21856f4eef0. * fixup: useBookerStoreContext and useInitializeBookerStoreContext for booker web wrapper * fixup: failing E2E tests * fixup: email embed breaking * fixup: troubleshooter crashing * replace useBookerstore with useBookerStoreContext --------- Co-authored-by: Rajiv Sahal <[email protected]> Co-authored-by: Ryukemeister <[email protected]> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Benny Joo <[email protected]>
120 lines
3.2 KiB
TypeScript
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/DatePicker";
|
|
|
|
import { render } from "../__tests__/test-utils";
|
|
import { DatePicker } from "./DatePicker";
|
|
|
|
vi.mock("@calcom/features/calendars/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()
|
|
);
|
|
});
|
|
});
|