57 lines
3.0 KiB
TypeScript
57 lines
3.0 KiB
TypeScript
import "@testing-library/jest-dom";
|
|
import { render, screen } from "@testing-library/react";
|
|
import { describe, expect, it } from "vitest";
|
|
import { createHotSwapDrillPage } from "@toolctrl/ui-mock";
|
|
import { HotSwapPageRenderer } from "./HotSwapPageRenderer";
|
|
|
|
describe("HotSwapPageRenderer", () => {
|
|
it("renders the ui-mock hot-swap drill descriptor through the ui-app registry shell", () => {
|
|
const descriptor = createHotSwapDrillPage();
|
|
const { container } = render(<HotSwapPageRenderer descriptor={descriptor} />);
|
|
|
|
const shell = container.querySelector('[data-ui-shell="hot-swap"]');
|
|
expect(shell).not.toBeNull();
|
|
expect(shell?.getAttribute("data-ui-source")).toBe("ui-app-registry");
|
|
expect(shell?.getAttribute("data-page-id")).toBe(descriptor.id);
|
|
expect(shell?.getAttribute("data-page-route")).toBe(descriptor.route);
|
|
expect(shell?.getAttribute("data-page-status")).toBe(descriptor.state.status);
|
|
});
|
|
|
|
it("derives counts from the descriptor registries via createShellRegistries", () => {
|
|
const descriptor = createHotSwapDrillPage();
|
|
const { container } = render(<HotSwapPageRenderer descriptor={descriptor} />);
|
|
|
|
const shell = container.querySelector('[data-ui-shell="hot-swap"]');
|
|
expect(shell?.getAttribute("data-sidebar-count")).toBe(String(descriptor.registries?.sidebar?.length ?? 0));
|
|
expect(shell?.getAttribute("data-breadcrumb-count")).toBe(String(descriptor.registries?.breadcrumbs?.length ?? 0));
|
|
expect(shell?.getAttribute("data-mobile-count")).toBe(String(descriptor.registries?.mobile?.length ?? 0));
|
|
expect(shell?.getAttribute("data-portal-count")).toBe(String(descriptor.registries?.portals?.length ?? 0));
|
|
});
|
|
|
|
it("renders each descriptor section (sidebar, breadcrumbs, header, cards, activity)", () => {
|
|
const descriptor = createHotSwapDrillPage();
|
|
const { container } = render(<HotSwapPageRenderer descriptor={descriptor} />);
|
|
|
|
expect(container.querySelector('[data-section="sidebar"]')).not.toBeNull();
|
|
expect(container.querySelector('[data-section="breadcrumbs"]')).not.toBeNull();
|
|
expect(container.querySelector('[data-section="header"]')).not.toBeNull();
|
|
expect(container.querySelector('[data-section="cards"]')).not.toBeNull();
|
|
expect(container.querySelector('[data-section="activity"]')).not.toBeNull();
|
|
|
|
const cards = container.querySelectorAll('[data-section="cards"] [data-card-value]');
|
|
expect(cards.length).toBe(descriptor.state.data?.cards.length ?? 0);
|
|
|
|
const activityItems = container.querySelectorAll('[data-section="activity"] li');
|
|
expect(activityItems.length).toBe(descriptor.state.data?.activity.length ?? 0);
|
|
});
|
|
|
|
it("renders the label keys from the descriptor as text nodes", () => {
|
|
const descriptor = createHotSwapDrillPage();
|
|
render(<HotSwapPageRenderer descriptor={descriptor} />);
|
|
|
|
// The renderer surfaces translation keys verbatim so the i18n layer can hydrate them later.
|
|
expect(screen.getByText(descriptor.titleKey!)).toBeInTheDocument();
|
|
expect(screen.getByText(descriptor.descriptionKey!)).toBeInTheDocument();
|
|
});
|
|
});
|