Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+99
@@ -0,0 +1,99 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { createRoutesStub, Link, Outlet } from "react-router";
|
||||
|
||||
import { HiveGridMeta } from "./HiveGridMeta";
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
document.head.querySelectorAll("title").forEach((title) => title.remove());
|
||||
});
|
||||
|
||||
describe("HiveGridMeta router integration", () => {
|
||||
it("uses a loader-only leaf title and renders exactly one document title", async () => {
|
||||
const Stub = createTitleRoutesStub({ leafData: { title: "Aufgaben" } });
|
||||
render(<Stub initialEntries={["/tasks"]} />);
|
||||
|
||||
await waitFor(() => expect(document.title).toBe("Aufgaben | HiveGrid"));
|
||||
expect(document.head.querySelectorAll("title")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("normalizes a leaf route's explicit meta output", async () => {
|
||||
const Stub = createTitleRoutesStub({ leafData: { title: "Kontakte | Application Starter" }, leafHasMeta: true });
|
||||
render(<Stub initialEntries={["/tasks"]} />);
|
||||
|
||||
await waitFor(() => expect(document.title).toBe("Kontakte | HiveGrid"));
|
||||
expect(document.head.querySelectorAll("title")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("inherits the root title when the leaf exposes no page title", async () => {
|
||||
const Stub = createTitleRoutesStub({ leafData: {} });
|
||||
render(<Stub initialEntries={["/tasks"]} />);
|
||||
|
||||
await waitFor(() => expect(document.title).toBe("HiveGrid"));
|
||||
expect(document.head.querySelectorAll("title")).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("updates the title after client-side navigation", async () => {
|
||||
const Stub = createRoutesStub([
|
||||
{
|
||||
id: "root",
|
||||
path: "/",
|
||||
Component: () => (
|
||||
<>
|
||||
<HiveGridMeta />
|
||||
<Link to="/contacts">Kontakte öffnen</Link>
|
||||
<Outlet />
|
||||
</>
|
||||
),
|
||||
loader: () => ({ metatags: [{ title: "HiveGrid" }] }),
|
||||
HydrateFallback: () => null,
|
||||
meta: ({ data }) => (data as { metatags: Array<{ title: string }> }).metatags,
|
||||
children: [
|
||||
{ id: "routes/tasks", path: "tasks", Component: () => <main>Tasks</main>, loader: () => ({ title: "Aufgaben" }) },
|
||||
{ id: "routes/contacts", path: "contacts", Component: () => <main>Contacts</main>, loader: () => ({ title: "Kontakte" }) },
|
||||
],
|
||||
},
|
||||
]);
|
||||
render(<Stub initialEntries={["/tasks"]} />);
|
||||
|
||||
await waitFor(() => expect(document.title).toBe("Aufgaben | HiveGrid"));
|
||||
fireEvent.click(screen.getByRole("link", { name: "Kontakte öffnen" }));
|
||||
await waitFor(() => expect(document.title).toBe("Kontakte | HiveGrid"));
|
||||
expect(document.head.querySelectorAll("title")).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
function createTitleRoutesStub({ leafData, leafHasMeta = false }: { leafData: Record<string, unknown>; leafHasMeta?: boolean }) {
|
||||
return createRoutesStub([
|
||||
{
|
||||
id: "root",
|
||||
path: "/",
|
||||
Component: () => (
|
||||
<>
|
||||
<HiveGridMeta />
|
||||
<Outlet />
|
||||
</>
|
||||
),
|
||||
loader: () => ({ metatags: [{ title: "HiveGrid" }] }),
|
||||
HydrateFallback: () => null,
|
||||
meta: ({ data }) => (data as { metatags: Array<{ title: string }> }).metatags,
|
||||
children: [
|
||||
{
|
||||
id: "routes/tasks",
|
||||
path: "tasks",
|
||||
Component: () => <main>Tasks</main>,
|
||||
loader: () => leafData,
|
||||
...(leafHasMeta
|
||||
? {
|
||||
meta: ({ data }: { data: unknown }) => [{ title: (data as { title: string }).title }],
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
}
|
||||
Reference in new issue
Block a user