* 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]>
106 lines
2.9 KiB
TypeScript
106 lines
2.9 KiB
TypeScript
import { render } from "@testing-library/react";
|
|
import type { RenderOptions } from "@testing-library/react";
|
|
import React from "react";
|
|
import type { ReactElement } from "react";
|
|
import { vi } from "vitest";
|
|
import type { StoreApi } from "zustand";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { BookerLayouts } from "@calcom/prisma/zod-utils";
|
|
|
|
import { BookerStoreContext } from "../BookerStoreProvider";
|
|
import type { BookerStore } from "../store";
|
|
|
|
interface CustomRenderOptions extends Omit<RenderOptions, "wrapper"> {
|
|
mockStore?: Partial<BookerStore>;
|
|
}
|
|
|
|
const createMockStore = (initialState?: Partial<BookerStore>): StoreApi<BookerStore> => {
|
|
let state: BookerStore = {
|
|
username: null,
|
|
eventSlug: null,
|
|
eventId: null,
|
|
verifiedEmail: null,
|
|
setVerifiedEmail: vi.fn(),
|
|
month: dayjs().format("YYYY-MM"),
|
|
setMonth: vi.fn(),
|
|
state: "loading",
|
|
setState: vi.fn(),
|
|
layout: BookerLayouts.MONTH_VIEW,
|
|
setLayout: vi.fn(),
|
|
selectedDate: null,
|
|
setSelectedDate: vi.fn(),
|
|
addToSelectedDate: vi.fn(),
|
|
selectedDatesAndTimes: null,
|
|
setSelectedDatesAndTimes: vi.fn(),
|
|
durationConfig: null,
|
|
selectedDuration: null,
|
|
setSelectedDuration: vi.fn(),
|
|
selectedTimeslot: null,
|
|
setSelectedTimeslot: vi.fn(),
|
|
tentativeSelectedTimeslots: [],
|
|
setTentativeSelectedTimeslots: vi.fn(),
|
|
recurringEventCount: null,
|
|
setRecurringEventCount: vi.fn(),
|
|
occurenceCount: null,
|
|
setOccurenceCount: vi.fn(),
|
|
dayCount: null,
|
|
setDayCount: vi.fn(),
|
|
rescheduleUid: null,
|
|
rescheduledBy: null,
|
|
bookingUid: null,
|
|
bookingData: null,
|
|
setBookingData: vi.fn(),
|
|
initialize: vi.fn(),
|
|
formValues: {},
|
|
setFormValues: vi.fn(),
|
|
isTeamEvent: false,
|
|
seatedEventData: {},
|
|
setSeatedEventData: vi.fn(),
|
|
isInstantMeeting: false,
|
|
org: null,
|
|
setOrg: vi.fn(),
|
|
timezone: null,
|
|
setTimezone: vi.fn(),
|
|
teamMemberEmail: null,
|
|
crmOwnerRecordType: null,
|
|
crmAppSlug: null,
|
|
crmRecordId: null,
|
|
isPlatform: false,
|
|
allowUpdatingUrlParams: true,
|
|
...initialState,
|
|
};
|
|
|
|
state.setMonth = vi.fn((month: string | null) => {
|
|
state.month = month;
|
|
});
|
|
|
|
return {
|
|
getState: () => state,
|
|
setState: vi.fn((updater) => {
|
|
if (typeof updater === "function") {
|
|
const newState = updater(state);
|
|
state = { ...state, ...newState };
|
|
} else {
|
|
state = { ...state, ...updater };
|
|
}
|
|
}),
|
|
subscribe: vi.fn(),
|
|
destroy: vi.fn(),
|
|
} as unknown as StoreApi<BookerStore>;
|
|
};
|
|
|
|
export const renderWithBookerStore = (ui: ReactElement, options?: CustomRenderOptions) => {
|
|
const mockStore = createMockStore(options?.mockStore);
|
|
|
|
const Wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
<BookerStoreContext.Provider value={mockStore}>{children}</BookerStoreContext.Provider>
|
|
);
|
|
|
|
return render(ui, { wrapper: Wrapper, ...options });
|
|
};
|
|
|
|
export * from "@testing-library/react";
|
|
|
|
export { renderWithBookerStore as render };
|