Open History to see the last commit
1import { renderToStaticMarkup } from "react-dom/server";
2import { expect, it, vi } from "vite-plus/test";
3
4const locale = vi.hoisted(() => ({ current: "fr" }));
5vi.mock(import("~/i18n/I18nProvider"), () => ({ useFormattingLocale: () => locale.current }));
6
7import { Calendar } from "./calendar";
8
9function renderNovember(formattingLocale: string) {
10 locale.current = formattingLocale;
11 const html = renderToStaticMarkup(
12 <Calendar mode="single" defaultMonth={new Date(2026, 10, 1)} weekStartsOn={1} />,
13 );
14 return {
15 grid: html.match(/<table[^>]*aria-label="([^"]*)"/)?.[1],
16 caption: html.match(/role="status"[^>]*>([^<]*)</)?.[1],
17 weekdays: [...html.matchAll(/<th [^>]*>([^<]*)<\/th>/g)].map((match) => match[1]),
18 };
19}
20
21it("labels the month and weekdays in the app language", () => {
22 expect(renderNovember("fr")).toEqual({
23 grid: "novembre 2026",
24 caption: "novembre 2026",
25 weekdays: ["lun.", "mar.", "mer.", "jeu.", "ven.", "sam.", "dim."],
26 });
27});
28
29it("keeps two-letter English weekdays", () => {
30 expect(renderNovember("en-US").weekdays).toEqual(["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"]);
31});
32
33it("names the grid's Gregorian month under a non-Gregorian host locale", () => {
34 const { grid, caption } = renderNovember("fa-IR");
35 expect(grid).toBe("نوامبر ۲۰۲۶");
36 expect(caption).toBe("نوامبر ۲۰۲۶");
37});