feat: migrate Calendar and calendar year picker
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// @vitest-environment node
|
||||
import { expect, it } from "vitest";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { CalendarDate } from "@internationalized/date";
|
||||
import {
|
||||
Calendar,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
} from "../packages/vue/src/index";
|
||||
it("renders month and year markup without browser globals and stable explicit dates", async () => {
|
||||
const value = new CalendarDate(2024, 2, 29);
|
||||
const app = createSSRApp({
|
||||
render: () =>
|
||||
h(
|
||||
Calendar,
|
||||
{
|
||||
defaultValue: value,
|
||||
defaultFocusedValue: value,
|
||||
locale: "en-US",
|
||||
timeZone: "UTC",
|
||||
},
|
||||
() => [
|
||||
h(CalendarHeader, () => h(CalendarHeading)),
|
||||
h(CalendarGrid, () => [h(CalendarGridHeader), h(CalendarGridBody)]),
|
||||
h(CalendarYearPickerGrid, () => h(CalendarYearPickerGridBody)),
|
||||
],
|
||||
),
|
||||
});
|
||||
const html = await renderToString(app);
|
||||
expect(html).toContain('data-date="2024-02-29"');
|
||||
expect(html).toContain('data-selected="true"');
|
||||
expect(html).toContain("February 2024");
|
||||
expect(html).toContain("inert");
|
||||
});
|
||||
it("renders the actual non-Gregorian weekday/month view and day windows on the server", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(
|
||||
Calendar,
|
||||
{
|
||||
defaultFocusedValue: new CalendarDate(2024, 2, 10),
|
||||
locale: "hi-IN-u-ca-indian",
|
||||
visibleDuration: { days: 3 },
|
||||
selectionAlignment: "start",
|
||||
},
|
||||
() =>
|
||||
h(CalendarGrid, () => [h(CalendarGridHeader), h(CalendarGridBody)]),
|
||||
),
|
||||
}),
|
||||
);
|
||||
expect(html.match(/data-slot="calendar-cell"/g) ?? []).toHaveLength(3);
|
||||
expect(html).toContain("2024-02-10");
|
||||
expect(html).not.toContain("Sunday");
|
||||
});
|
||||
Reference in New Issue
Block a user