feat: migrate Toast and Table with reviewed state focus and SSR contracts
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { createSSRApp, h, nextTick } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
ToastProvider,
|
||||
ToastQueue,
|
||||
Table,
|
||||
TableContent,
|
||||
TableHeader,
|
||||
TableColumn,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableCell,
|
||||
} from "../packages/vue/src";
|
||||
it("hydrates toast and table with stable content, then keyboard selection works", async () => {
|
||||
let queue = new ToastQueue();
|
||||
queue.add({ title: "Hydrated notice" }, { timeout: 0 });
|
||||
const Root = {
|
||||
render: () =>
|
||||
h("main", [
|
||||
h(ToastProvider, { queue }),
|
||||
h(Table, () =>
|
||||
h(TableContent, { selectionMode: "multiple" }, () => [
|
||||
h(TableHeader, () =>
|
||||
h(TableColumn, { id: "name", isRowHeader: true }, () => "Name"),
|
||||
),
|
||||
h(TableBody, () =>
|
||||
h(TableRow, { rowKey: 0 }, () => h(TableCell, () => "Zero")),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
};
|
||||
const host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
host.innerHTML = await renderToString(createSSRApp(Root));
|
||||
queue.destroy();
|
||||
queue = new ToastQueue();
|
||||
queue.add({ title: "Hydrated notice" }, { timeout: 0 });
|
||||
const error = vi.spyOn(console, "error"),
|
||||
warn = vi.spyOn(console, "warn");
|
||||
const app = createSSRApp(Root);
|
||||
app.mount(host);
|
||||
await nextTick();
|
||||
expect(
|
||||
[...error.mock.calls, ...warn.mock.calls].flat().join(" "),
|
||||
).not.toMatch(/hydration|mismatch/i);
|
||||
const row = host.querySelector("tbody tr")!;
|
||||
row.dispatchEvent(new KeyboardEvent("keydown", { key: " ", bubbles: true }));
|
||||
await nextTick();
|
||||
expect(row.getAttribute("aria-selected")).toBe("true");
|
||||
app.unmount();
|
||||
queue.destroy();
|
||||
host.remove();
|
||||
error.mockRestore();
|
||||
warn.mockRestore();
|
||||
});
|
||||
Reference in New Issue
Block a user