This line's guide images already come from production components, and the maintenance branch owns its 2.x screenshots and README stills. The fixture under site/film/ui still built the 2.x room here, from components the 3.0 product's entry no longer reaches, and was the one thing outside previews and tests that kept them. Gone: the fixture, its entry, page and license output in the website build and its include in the scripts' TypeScript project; the 14 modules only it kept (the 2.x status model, presence and viewer presentation, and the playback bar, room chip, couch, status indicator, host toolbar and room interactions panel); and what only they kept, followed until nothing more fell out: the title-frame catalogues of each locale with their reader and useDocumentTitle, 109 copy keys, one stylesheet and the rules of 130 classes, Row, the TV frame's indicator slot, the SFU route and relay-volunteer sections of PlaybackSettings, and the shared-protocol shapes only they read. Kept: the public film and its build, the product's own title (usePageTitle with composeDocumentTitle), and every preview section and test assertion about product components. The playback preview and the status scenarios existed for the removed modules and went. Four test files held only removed modules and went, with the title hook's; four mixed files lost the cases about them. How it was established: the product's entry reaches 303 files before and after; the type check proves the copy keys, since every use is typed against the English catalogue; every removed rule belongs to a class no source file writes, and no class still written lost every rule it had, except lr-playback-compact-picture, whose only rules needed the old bar as an ancestor. Documents: the three that described the fixture no longer do and keep the rule that current screenshots use real components. In the visual language standard two rows of the text-only table described the title catalogues and the status model and are removed, with the sentence that named the presence module, so that its links resolve.
134 lines
6.9 KiB
TypeScript
134 lines
6.9 KiB
TypeScript
import { createElement } from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
import { RouteGraph } from "../src/client/components/living/RouteGraph.tsx";
|
|
import { participantColor } from "../src/client/components/living/participant-color.ts";
|
|
import { routeGraphLayout, topologyLayoutForWidth, type RouteGraphNode, type RouteGraphEdge } from "../src/client/components/living/route-tree-layout.ts";
|
|
import { setCopy } from "../src/client/ui/copy.ts";
|
|
|
|
afterEach(() => setCopy({ lang: "zh" }));
|
|
|
|
function accessibleRoutes(html: string): string[] {
|
|
const list = html.split('<ul class="visually-hidden">')[1].split("</ul>")[0];
|
|
return Array.from(list.matchAll(/<li>(.*?)<\/li>/gs), ([, item]) => item.replace(/<[^>]+>/g, ""));
|
|
}
|
|
|
|
describe("topology labels and layout", () => {
|
|
it("uses real-size narrow coordinates without compressing deep trees", () => {
|
|
const narrow = topologyLayoutForWidth(260);
|
|
const desktop = topologyLayoutForWidth(640);
|
|
|
|
expect(narrow).toEqual({
|
|
baseWidth: 260,
|
|
hostX: 65,
|
|
columnGap: 130,
|
|
rightLabelReserve: 65,
|
|
maxVisibleLabelCodePoints: 10,
|
|
});
|
|
expect(
|
|
narrow.hostX + narrow.columnGap + narrow.rightLabelReserve,
|
|
).toBeLessThanOrEqual(narrow.baseWidth);
|
|
expect(
|
|
narrow.hostX + narrow.columnGap * 3 + narrow.rightLabelReserve,
|
|
).toBeGreaterThan(narrow.baseWidth);
|
|
expect(desktop.baseWidth).toBe(640);
|
|
expect(desktop.hostX).toBe(210);
|
|
expect(desktop.columnGap).toBe(220);
|
|
expect(desktop.rightLabelReserve).toBe(210);
|
|
});
|
|
|
|
it("derives symmetric topology insets at every responsive width", () => {
|
|
for (const width of [260, 390, 520, 640]) {
|
|
const layout = topologyLayoutForWidth(width);
|
|
expect(layout.hostX).toBe(layout.rightLabelReserve);
|
|
expect(
|
|
layout.hostX * 2 + layout.columnGap,
|
|
).toBe(layout.baseWidth);
|
|
}
|
|
});
|
|
|
|
it("keeps topology geometry continuous across the former viewport breakpoint", () => {
|
|
const atBreakpoint = topologyLayoutForWidth(640);
|
|
const afterBreakpoint = topologyLayoutForWidth(641);
|
|
|
|
expect(afterBreakpoint).toEqual(atBreakpoint);
|
|
expect(topologyLayoutForWidth(390).baseWidth).toBe(390);
|
|
});
|
|
});
|
|
|
|
describe("RouteGraph", () => {
|
|
it("lays out the selected parent while retaining both real candidate edges", () => {
|
|
const nodes = [
|
|
{ id: "source", label: "Source" }, { id: "relay", label: "Relay" },
|
|
{ id: "viewer", label: "Viewer" }, { id: "helper", label: "Viewer App" },
|
|
];
|
|
const edges = [
|
|
{ from: "helper", to: "viewer", selected: false, ready: true, presentation: true },
|
|
{ from: "source", to: "helper", selected: false, ready: false },
|
|
{ from: "source", to: "relay", selected: true, ready: true },
|
|
{ from: "relay", to: "viewer", selected: true, ready: true },
|
|
];
|
|
const layout = routeGraphLayout(nodes, "source", edges, 640);
|
|
expect(layout.points.get("viewer")!.x).toBeGreaterThan(layout.points.get("relay")!.x);
|
|
expect(layout.points.get("helper")!.x).toBe(layout.points.get("relay")!.x);
|
|
const html = renderToStaticMarkup(createElement(RouteGraph, { nodes, rootId: "source", edges }));
|
|
expect(html.match(/class="lr-route-edge /g)).toHaveLength(4);
|
|
expect(html).toContain('class="lr-route-edge is-p2p is-pending is-presentation"');
|
|
expect(html.match(/class="lr-route-edge is-p2p"/g)).toHaveLength(2);
|
|
const viewerRoutes = accessibleRoutes(html).find(item => item.startsWith("Viewer ←"));
|
|
expect(viewerRoutes).toContain("← Relay ·");
|
|
expect(viewerRoutes).toContain("← Viewer App ·");
|
|
expect(html).not.toContain("SFU");
|
|
});
|
|
|
|
it("keeps distinct endpoint controls with their stable participant identity color", () => {
|
|
const nodes = [{ id: "source", label: "Source", host: true },
|
|
{ id: "app", label: "Friend App", identity: "friend-user" },
|
|
{ id: "page", label: "Friend Browser", identity: "friend-user", you: true }];
|
|
const edges = [{ from: "source", to: "app", selected: true, ready: true },
|
|
{ from: "app", to: "page", selected: true, ready: true, presentation: true }];
|
|
const html = renderToStaticMarkup(createElement(RouteGraph, { nodes, rootId: "source", edges,
|
|
selectedId: "page", selectableIds: ["app", "page"], onSelect: () => undefined }));
|
|
expect(html.match(/class="lr-person"/g)).toHaveLength(3);
|
|
expect(html.split(participantColor("friend-user"))).toHaveLength(3);
|
|
expect(html.match(/class="lr-route-hit"/g)).toHaveLength(2);
|
|
expect(html).toContain('class="lr-route-node is-selected"');
|
|
expect(html).toContain('class="lr-route-you"');
|
|
expect(html).toContain('class="lr-route-edge is-p2p is-presentation"');
|
|
});
|
|
|
|
it("keeps a deep graph and its pending alternative inside the narrow outline", () => {
|
|
const nodes: RouteGraphNode[] = Array.from({ length: 21 }, (_, index) => ({ id: `${index}`, label: `Person ${index}` }));
|
|
const edges: RouteGraphEdge[] = nodes.slice(1).map((node, index) => ({ from: `${index}`, to: node.id, selected: true, ready: true }));
|
|
nodes.push({ id: "helper", label: "New App" });
|
|
edges.push({ from: "0", to: "helper", selected: false, ready: false },
|
|
{ from: "helper", to: "20", selected: false, ready: false, presentation: true });
|
|
const layout = routeGraphLayout(nodes, "0", edges, 260);
|
|
expect(layout.outline).toBe(true);
|
|
expect(layout.width).toBe(260);
|
|
expect(new Set([...layout.points.values()].map(point => point.y)).size).toBe(nodes.length);
|
|
expect([...layout.points.values()].every(point => point.x >= 0 && point.x + 40 < layout.width)).toBe(true);
|
|
const html = renderToStaticMarkup(createElement(RouteGraph, { nodes, rootId: "0", edges }));
|
|
expect(html.match(/class="lr-route-edge /g)).toHaveLength(edges.length);
|
|
expect(html).not.toMatch(/NaN|undefined/);
|
|
});
|
|
|
|
it("shares the solid SFU rail only between ready branches without widening the panel", () => {
|
|
const nodes = [{ id: "host", label: "Host", host: true }, { id: "sfu", label: "SFU", kind: "sfu" as const },
|
|
{ id: "a", label: "A" }, { id: "b", label: "B" }, { id: "c", label: "C" }];
|
|
const edges: RouteGraphEdge[] = [{ from: "host", to: "sfu", selected: true, ready: true, route: "sfu" },
|
|
...["a", "b", "c"].map(to => ({ from: "sfu", to, selected: true, ready: false, route: "sfu" as const }))];
|
|
const render = () => renderToStaticMarkup(createElement(RouteGraph, { nodes, rootId: "host", edges }));
|
|
const pending = render();
|
|
expect(pending.match(/class="lr-route-edge is-sfu"/g)).toHaveLength(1);
|
|
expect(pending.match(/class="lr-route-edge is-sfu is-pending"/g)).toHaveLength(3);
|
|
edges[1].ready = edges[2].ready = true;
|
|
const html = render();
|
|
expect(html).toContain('viewBox="0 0 640 ');
|
|
expect(html.match(/class="lr-route-sfu"/g)).toHaveLength(1);
|
|
expect(html.match(/class="lr-route-edge is-sfu"/g)).toHaveLength(5);
|
|
expect(html.match(/d="M [^"]+ Q [^"]+" class="lr-route-edge is-sfu is-pending"/g)).toHaveLength(1);
|
|
});
|
|
});
|