Files
calendar/packages/features/calendars/DatePicker.test.tsx
T
Alex van AndelandGitHub 0772e1d168 fix: skip when browsing month has no available slots (#19626)
* fix: skip when browsing month has no available slots

* Fix zustand error + add wip tests

* Fix issue with using brows
ingDate too early

* Use slots instead of schedule return types to remove hard coupling to tRPC

* Some await fixes + use type definition from extended core feature

* Move useNextMonth to custom hook

* Add unit tests to cover the next month scenario

* Use changed interface, schedule -> slots,isLoading

* Return no-op until ready
2025-03-25 17:28:50 +00:00

42 lines
1.5 KiB
TypeScript

import { render } from "@testing-library/react";
import dayjs from "@calcom/dayjs";
import { DatePicker } from "./DatePicker";
const noop = () => {
/* noop */
};
describe("Tests for DatePicker Component", () => {
test("Should render correctly with default date", async () => {
const testDate = dayjs("2024-02-20");
const { getByTestId } = render(<DatePicker onChange={noop} browsingDate={testDate} locale="en" />);
const selectedMonthLabel = getByTestId("selected-month-label");
await expect(selectedMonthLabel).toHaveAttribute("dateTime", testDate.format("YYYY-MM"));
});
test("Should render with the minimum date if browsingDate < minDate", async () => {
const testDate = dayjs("2024-02-20");
const minDate = dayjs("2025-02-10");
const { getByTestId } = render(
<DatePicker onChange={noop} browsingDate={testDate} minDate={minDate.toDate()} locale="en" />
);
const selectedMonthLabel = getByTestId("selected-month-label");
await expect(selectedMonthLabel).toHaveAttribute("dateTime", minDate.format("YYYY-MM"));
});
test("Should render with the browsingDate date if browsingDate >= minDate", async () => {
const testDate = dayjs("2025-03-20");
const minDate = dayjs("2025-02-10");
const { getByTestId } = render(
<DatePicker onChange={noop} browsingDate={testDate} minDate={minDate} locale="en" />
);
const selectedMonthLabel = getByTestId("selected-month-label");
await expect(selectedMonthLabel).toHaveAttribute("dateTime", testDate.format("YYYY-MM"));
});
});