feat: migrate Calendar and calendar year picker
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { createSSRApp, defineComponent, h, type Component } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { CalendarDate } from "@internationalized/date";
|
||||
import {
|
||||
Calendar,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
} from "../packages/vue/src/index";
|
||||
const demos = import.meta.glob("../apps/docs/demos/calendar-*.vue", {
|
||||
eager: true,
|
||||
import: "default",
|
||||
}) as Record<string, Component>;
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
it("mounts all nineteen baseline demos together without duplicate IDs or Vue warnings", async () => {
|
||||
expect(Object.keys(demos)).toHaveLength(19);
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(
|
||||
"div",
|
||||
Object.entries(demos).map(([key, demo]) => h(demo, { key })),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
await flushPromises();
|
||||
const ids = Array.from(document.querySelectorAll("[id]")).map((e) => e.id);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
});
|
||||
it("hydrates an explicitly dated calendar without replacing the server grid", async () => {
|
||||
const Root = defineComponent({
|
||||
render: () =>
|
||||
h(
|
||||
Calendar,
|
||||
{
|
||||
defaultFocusedValue: new CalendarDate(2024, 2, 10),
|
||||
locale: "en-US",
|
||||
timeZone: "UTC",
|
||||
},
|
||||
() =>
|
||||
h(CalendarGrid, () => [h(CalendarGridHeader), h(CalendarGridBody)]),
|
||||
),
|
||||
});
|
||||
const host = document.createElement("div");
|
||||
host.innerHTML = await renderToString(createSSRApp(Root));
|
||||
document.body.append(host);
|
||||
const grid = host.querySelector("table");
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
const app = createSSRApp(Root);
|
||||
app.mount(host);
|
||||
await flushPromises();
|
||||
expect(host.querySelector("table")).toBe(grid);
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
app.unmount();
|
||||
});
|
||||
Reference in New Issue
Block a user