Skip to content

Commit

Permalink
feat(calendar): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
wingkwong committed Jun 26, 2024
1 parent 336a4ff commit 5c111b9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/components/calendar/__tests__/calendar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {render, act, fireEvent} from "@testing-library/react";
import {CalendarDate, isWeekend} from "@internationalized/date";
import {triggerPress, keyCodes} from "@nextui-org/test-utils";
import {useLocale} from "@react-aria/i18n";
import {NextUIProvider} from "@nextui-org/system";

import {Calendar as CalendarBase, CalendarProps} from "../src";

Expand All @@ -16,6 +17,20 @@ const Calendar = React.forwardRef((props: CalendarProps, ref: React.Ref<HTMLDivE

Calendar.displayName = "Calendar";

const CalendarWithLocale = React.forwardRef(
(props: CalendarProps & {locale: string}, ref: React.Ref<HTMLDivElement>) => {
const {locale, ...otherProps} = props;

return (
<NextUIProvider locale={locale}>
<CalendarBase {...otherProps} ref={ref} disableAnimation />
</NextUIProvider>
);
},
);

CalendarWithLocale.displayName = "CalendarWithLocale";

describe("Calendar", () => {
beforeAll(() => {
jest.useFakeTimers();
Expand Down Expand Up @@ -418,5 +433,25 @@ describe("Calendar", () => {

expect(description).toBe("Selected date unavailable.");
});

it("should display the correct year and month in showMonthAndYearPickers with locale", () => {
const {getByRole} = render(
<CalendarWithLocale
showMonthAndYearPickers
defaultValue={new CalendarDate(2024, 6, 26)}
locale="th-TH-u-ca-buddhist"
/>,
);

const header = document.querySelector<HTMLButtonElement>(`button[data-slot="header"]`)!;

triggerPress(header);

const month = getByRole("button", {name: "มิถุนายน"});
const year = getByRole("button", {name: "พ.ศ. 2567"});

expect(month).toHaveAttribute("data-value", "6");
expect(year).toHaveAttribute("data-value", "2567");
});
});
});

0 comments on commit 5c111b9

Please sign in to comment.