Files
calendar/packages/features/bookings/Booker/utils/getPrefetchMonthCount.test.ts
T
98b6d63164 refactor: apply biome formatting to packages/features (#27844)
* refactor: apply biome formatting to packages/features (batch 1 - small subdirs)

Format small subdirectories in packages/features: di, flags, holidays, oauth,
settings, users, assignment-reason, selectedCalendar, hashedLink, host, form,
form-builder, availability, data-table, pbac, schedules, troubleshooter,
eventtypes, calendar-subscription, and root-level files.

Also includes straggler apps/web BookEventForm.tsx.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 2 - medium subdirs)

Format medium subdirectories in packages/features: auth, credentials,
calendars, routing-forms, routing-trace, attributes, watchlist, calAIPhone,
tasker, and webhooks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 3 - bookings + insights)

Format bookings and insights subdirectories in packages/features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 4 - ee)

Format packages/features/ee subdirectory covering billing, workflows,
organizations, teams, managed-event-types, round-robin, dsync,
integration-attribute-sync, and payments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 5 - booking-audit part 1)

Format booking-audit di, actions, common, dto, repository, and types
subdirectories in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: apply biome formatting to packages/features (batch 6 - booking-audit part 2)

Format booking-audit service subdirectory in packages/features/booking-audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 15:47:14 +01:00

110 lines
4.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { BookerLayouts } from "@calcom/prisma/zod-utils";
import { getPrefetchMonthCount } from "./getPrefetchMonthCount";
describe("getPrefetchMonthCount", () => {
describe("COLUMN_VIEW layout", () => {
it("should return 2 when months are different", () => {
const result = getPrefetchMonthCount(BookerLayouts.COLUMN_VIEW, "selecting_date", 1, 2, false);
expect(result).toBe(2);
});
it("should return undefined when months are the same", () => {
const result = getPrefetchMonthCount(BookerLayouts.COLUMN_VIEW, "selecting_date", 5, 5, false);
expect(result).toBe(undefined);
});
it("should return 2 regardless of bookerState when months are different", () => {
expect(getPrefetchMonthCount(BookerLayouts.COLUMN_VIEW, "selecting_time", 3, 4, false)).toBe(2);
expect(getPrefetchMonthCount(BookerLayouts.COLUMN_VIEW, "booking", 7, 8, false)).toBe(2);
});
it("should return 2 even when prefetchNextMonth is true", () => {
expect(getPrefetchMonthCount(BookerLayouts.COLUMN_VIEW, "selecting_time", 3, 4, true)).toBe(2);
});
});
describe("WEEK_VIEW layout", () => {
it("should return undefined when state is selecting_time", () => {
const result = getPrefetchMonthCount(BookerLayouts.WEEK_VIEW, "selecting_time", 1, 2, false);
expect(result).toBe(undefined);
});
it("should return undefined when state is not selecting_time", () => {
const result = getPrefetchMonthCount(BookerLayouts.WEEK_VIEW, "selecting_date", 1, 2, false);
expect(result).toBe(undefined);
});
it("should return undefined even with different months", () => {
const result = getPrefetchMonthCount(BookerLayouts.WEEK_VIEW, "booking", 0, 11, false);
expect(result).toBe(undefined);
});
});
describe("MONTH_VIEW layout with selecting_time state", () => {
it("should return 2 when months are different and NOT prefetching", () => {
const result = getPrefetchMonthCount(BookerLayouts.MONTH_VIEW, "selecting_time", 3, 4, false);
expect(result).toBe(2);
});
it("should return undefined when months are different but ALREADY prefetching", () => {
const result = getPrefetchMonthCount(BookerLayouts.MONTH_VIEW, "selecting_time", 3, 4, true);
expect(result).toBe(undefined);
});
it("should return undefined when months are the same", () => {
const result = getPrefetchMonthCount(BookerLayouts.MONTH_VIEW, "selecting_time", 6, 6, false);
expect(result).toBe(undefined);
});
});
describe("MONTH_VIEW layout with other states", () => {
it("should return undefined when state is selecting_date", () => {
const result = getPrefetchMonthCount(BookerLayouts.MONTH_VIEW, "selecting_date", 1, 2, false);
expect(result).toBe(undefined);
});
it("should return undefined when state is booking", () => {
const result = getPrefetchMonthCount(BookerLayouts.MONTH_VIEW, "booking", 1, 2, false);
expect(result).toBe(undefined);
});
});
describe("invalid month inputs", () => {
it("should return undefined when first month is NaN", () => {
const result = getPrefetchMonthCount(BookerLayouts.COLUMN_VIEW, "selecting_date", NaN, 5, false);
expect(result).toBe(undefined);
});
it("should return undefined when second month is NaN", () => {
const result = getPrefetchMonthCount(BookerLayouts.COLUMN_VIEW, "selecting_date", 5, NaN, false);
expect(result).toBe(undefined);
});
it("should return undefined when both months are invalid", () => {
const result = getPrefetchMonthCount(
BookerLayouts.COLUMN_VIEW,
"selecting_time",
Infinity,
-Infinity,
false
);
expect(result).toBe(undefined);
});
});
describe("edge cases", () => {
it("should handle month transitions (11 to 0)", () => {
const result = getPrefetchMonthCount(BookerLayouts.COLUMN_VIEW, "selecting_date", 11, 0, false);
expect(result).toBe(2);
});
it("should handle negative month numbers if they are different", () => {
const result = getPrefetchMonthCount(BookerLayouts.COLUMN_VIEW, "selecting_date", -1, 5, false);
expect(result).toBe(2);
});
});
});