Files
calendar/packages/features/bookings/Booker/hooks/useStableTimezone.test.ts
T
+3
Syed Ali ShahbazGitHubali@cal.com <alishahbaz7@gmail.com>ali@cal.com <alishahbaz7@gmail.com>ali@cal.com <alishahbaz7@gmail.com>ali@cal.com <alishahbaz7@gmail.com>ali@cal.com <alishahbaz7@gmail.com>ali@cal.com <alishahbaz7@gmail.com>ali@cal.com <alishahbaz7@gmail.com>hackice20YashMorganDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
4c73695d3a fix: refresh slots on timezone change for booker timezone restrictions (#27491)
* fix: refresh slots on timezone change for booker timezone restrictions

* refactor: use useMemo for timezone change detection

* revert: remove unnecessary formatting changes

* feat: add timezone refresh for platform components

Add timezone change detection and slot refresh to BookerPlatformWrapper
and EventTypeCalendarViewComponent to handle restriction schedules with
useBookerTimezone enabled.

* refactor: extract timezone slot refresh logic into reusable hook

* Update packages/platform/atoms/calendar-view/EventTypeCalendarViewComponent.tsx

Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>

* Update packages/platform/atoms/calendar-view/EventTypeCalendarViewComponent.tsx

Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>

* fix

* fix: prevent unnecessary getSchedule calls when useBookerTimezone is disabled

* fix: add timezone fields to BookerEvent type

* fix: add missing properties to BookerEvent and BookerEventProfile types

* trying to fix type errors

* Add restrictionScheduleId and useBookerTimezone fields

* fix: correct import path for useBookerTime hook

Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>

* fix: explicitly include restrictionScheduleId and useBookerTimezone in getPublicEvent return

Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>

* chore: trigger fresh CI build

Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>

* fix: cast event.data to BookerEvent for timezone fields access

Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>

* refactor: address review feedback for timezone slot refresh

Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>

* refactor: add explicit return type to event handler to ensure type propagation

Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>

* refactor: extract useStableTimezone hook and remove dead timezone detection code

Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>

---------

Co-authored-by: hackice20 <yashkam431@gmail.com>
Co-authored-by: Yash <116657771+hackice20@users.noreply.github.com>
Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-02-17 07:46:40 -03:00

75 lines
2.6 KiB
TypeScript

/**
* @vitest-environment jsdom
*/
import { renderHook } from "@testing-library/react";
import { describe, it, expect } from "vitest";
import { useStableTimezone } from "./useStableTimezone";
describe("useStableTimezone", () => {
it("returns the raw timezone when no restriction schedule is provided", () => {
const { result } = renderHook(() => useStableTimezone("America/New_York"));
expect(result.current).toBe("America/New_York");
});
it("returns the raw timezone when restriction schedule is undefined", () => {
const { result } = renderHook(() => useStableTimezone("America/New_York", undefined));
expect(result.current).toBe("America/New_York");
});
it("returns the raw timezone when restriction schedule id is null", () => {
const { result } = renderHook(() =>
useStableTimezone("America/New_York", { id: null, useBookerTimezone: false })
);
expect(result.current).toBe("America/New_York");
});
it("returns the raw timezone when restriction schedule id is 0", () => {
const { result } = renderHook(() =>
useStableTimezone("America/New_York", { id: 0, useBookerTimezone: false })
);
expect(result.current).toBe("America/New_York");
});
it("returns the raw timezone when useBookerTimezone is true (timezone should follow the booker)", () => {
const { result } = renderHook(() =>
useStableTimezone("America/New_York", { id: 1, useBookerTimezone: true })
);
expect(result.current).toBe("America/New_York");
});
it("pins to initial timezone when restriction schedule exists and useBookerTimezone is false", () => {
let timezone = "America/New_York";
const { result, rerender } = renderHook(() =>
useStableTimezone(timezone, { id: 1, useBookerTimezone: false })
);
expect(result.current).toBe("America/New_York");
timezone = "Europe/London";
rerender();
expect(result.current).toBe("America/New_York");
});
it("follows timezone changes when useBookerTimezone is true", () => {
let timezone = "America/New_York";
const { result, rerender } = renderHook(() =>
useStableTimezone(timezone, { id: 1, useBookerTimezone: true })
);
expect(result.current).toBe("America/New_York");
timezone = "Europe/London";
rerender();
expect(result.current).toBe("Europe/London");
});
it("follows timezone changes when there is no restriction schedule", () => {
let timezone = "America/New_York";
const { result, rerender } = renderHook(() => useStableTimezone(timezone));
expect(result.current).toBe("America/New_York");
timezone = "Europe/London";
rerender();
expect(result.current).toBe("Europe/London");
});
});