// @vitest-environment jsdom import { cleanup, render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import type { Edge, Node } from "@xyflow/react"; import { afterEach, describe, expect, it, vi } from "vitest"; import { GraphListView, nodeAriaLabel } from "./GraphListView"; import type { ServiceNodeData } from "./ServiceNode"; const data = (name: string, status: ServiceNodeData["status"], extra: Partial = {}): ServiceNodeData => ({ name, status, kind: "http", latency: null, dependencyCount: 0, rootCause: false, impacted: false, group: null, criticality: "medium", flapping: false, category: "service", ...extra, }); const nodes: Node[] = [ { id: "db", position: { x: 0, y: 0 }, data: data("PostgreSQL", "down", { rootCause: true }) }, { id: "api", position: { x: 0, y: 0 }, data: data("API", "degraded", { impacted: true, latency: 812.4 }) }, ]; const edges: Edge[] = [{ id: "db-api", source: "db", target: "api" }]; afterEach(cleanup); describe("graph text alternative", () => { it("names every node with its status and dependencies", () => { render( undefined} />); const region = screen.getByRole("region", { name: "Topologie als lijst" }); const items = region.querySelectorAll("li"); expect([...items].map((item) => item.querySelector("strong")?.textContent)).toEqual(["API", "PostgreSQL"]); expect(screen.getByText("Hangt af van PostgreSQL")).toBeTruthy(); expect(screen.getByRole("button", { name: /Uitgevallen PostgreSQL Hoofdoorzaak/ })).toBeTruthy(); }); it("opens a node with the keyboard", async () => { const onOpen = vi.fn(); render(); const user = userEvent.setup(); await user.tab(); await user.keyboard("{Enter}"); expect(onOpen).toHaveBeenCalledWith(nodes[1]); }); it("gives canvas nodes a spoken label", () => { expect(nodeAriaLabel(nodes[0].data as ServiceNodeData)).toBe("Service PostgreSQL, Uitgevallen, waarschijnlijke hoofdoorzaak"); expect(nodeAriaLabel(nodes[1].data as ServiceNodeData)).toBe("Service API, Verminderd, geraakt, 812 ms"); }); });