Files
heroui-vue/tests/date-foundation-ssr.test.ts
T
2026-10-23 23:56:18 +08:00

64 lines
2.5 KiB
TypeScript

// @vitest-environment node
import { describe, it, expect } from "vitest";
import { createSSRApp, h } from "vue";
import { renderToString } from "@vue/server-renderer";
import { CalendarDate, parseZonedDateTime } from "@internationalized/date";
import Field from "../packages/vue/tests/fixtures/DateFieldFoundation.vue";
import Calendar from "../packages/vue/tests/fixtures/CalendarFoundation.vue";
import Accepted from "../packages/vue/tests/fixtures/AcceptedDateFieldFoundation.vue";
const initial = new CalendarDate(2024, 2, 10);
describe("date foundation actual node SSR", () => {
it("renders full segmented date without browser globals", async () => {
expect(typeof window).toBe("undefined");
const html = await renderToString(
createSSRApp(Field, {
defaultValue: initial,
locale: "en-US",
name: "date",
}),
);
expect(html.match(/role="spinbutton"/g)).toHaveLength(3);
expect(html).toContain('value="2024-02-10"');
expect(html).toContain('aria-label="Date audit"');
});
it("renders leap month cells and selected date on the server", async () => {
const html = await renderToString(
createSSRApp(Calendar, {
defaultValue: initial,
defaultPlaceholder: initial,
locale: "en-US",
}),
);
expect(html).toContain('data-value="2024-02-29"');
expect(html).toContain('data-selected="true"');
// Installed CalendarGrid uses application, not grid; public ARIA needs explicit review.
expect(html).toContain('role="application"');
expect(html).toContain('role="gridcell"');
});
it("keeps SSR IDs stable and independent across same-page instances", async () => {
const app = () =>
createSSRApp({
render: () =>
h("main", [
h(Field, { defaultValue: initial }),
h(Field, { defaultValue: initial }),
]),
});
const first = await renderToString(app());
expect(first).toBe(await renderToString(app()));
const ids = [...first.matchAll(/ id="([^"]+)"/g)].map((m) => m[1]);
expect(new Set(ids).size).toBe(ids.length);
});
it("serializes the adapted complete zone-bearing model on SSR", async () => {
const value = parseZonedDateTime(
"2024-03-10T01:30:45-08:00[America/Los_Angeles]",
);
const html = await renderToString(
createSSRApp(Accepted, { defaultValue: value, name: "date" }),
);
expect(html).toContain(
'type="hidden" name="date" value="2024-03-10T01:30:45-08:00[America/Los_Angeles]"',
);
});
});