Files
piik/tests/metric-presentation.test.ts
T
AAA ab66c415f3 refactor(client): remove components only the previews reached
PawnDetail, RoomCodeInput, RouteTree, ShareFailureHelp and ViewerOverview,
the room voice panel and its connection details, the participant topology,
the relay volunteer limits and the media failure resolver were reached only
from the development previews and their tests: an import trace from the
product entry without its DEV routes, from site/ and from scripts/ reaches
none of them. Their preview sections, the room voice preview hook and the
troubleshooting checks that only fed the removed dialog go with them, along
with their tests, their styles and the 51 copy keys nothing else uses, in
all five locales.

The document title helper stays: it is also preview-only today, but the
visual language standard names it as the owner of document titles.
2026-11-25 18:44:03 +08:00

56 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { beforeEach, describe, expect, it } from "vitest";
import { ConnectionSummaryCells, MetricCells } from "../src/client/components/living/Metrics";
import { EMPTY_METRICS } from "../src/client/types";
import { setCopy, t } from "../src/client/ui/copy";
beforeEach(() => setCopy({ lang: "en" }));
describe("observed metric presentation", () => {
it("labels measured sender output and receiver decoding across details and summaries", () => {
const samples = [60, 120].map(framesPerSecond => ({
connectionId: String(framesPerSecond), metrics: { ...EMPTY_METRICS, framesPerSecond },
}));
for (const [direction, label] of [["send", "Output FPS"], ["receive", "Decoded FPS"]] as const) {
const detail = renderToStaticMarkup(createElement(MetricCells, {
direction, metrics: samples[1]!.metrics, expanded: false,
}));
expect(detail).toContain(label);
expect(detail).toContain("120.0 fps");
const summary = renderToStaticMarkup(createElement(ConnectionSummaryCells, {
direction, media: "video", samples,
}));
expect(summary).toContain(label + " range");
expect(summary).toContain("60.0–120.0 fps");
const missing = renderToStaticMarkup(createElement(MetricCells, {
direction, metrics: EMPTY_METRICS, expanded: false,
}));
expect(missing).not.toContain(label);
expect(missing).not.toMatch(/\d fps/);
}
});
it("reports dropped frames from the current sampling interval, not the connection lifetime", () => {
const render = (intervalFramesDropped: number | null) => renderToStaticMarkup(createElement(MetricCells, {
metrics: { ...EMPTY_METRICS, framesDropped: 300, intervalFramesDropped },
direction: "receive", expanded: true, onToggle() {},
}));
expect(render(2)).toContain(`${t("en", "stats.dropped")} · 2 `);
expect(render(0)).toContain(`${t("en", "stats.dropped")} · 0 `);
expect(render(null)).not.toContain(t("en", "stats.dropped"));
expect(render(2)).not.toContain(`${t("en", "stats.dropped")} · 300`);
});
it("keeps an unrecognized sender reason distinct from no limitation", () => {
const render = (qualityLimitationReason: string) => renderToStaticMarkup(createElement(MetricCells, {
metrics: { ...EMPTY_METRICS, qualityLimitationReason },
direction: "send", expanded: true, onToggle() {},
}));
expect(render("none")).toContain(t("en", "stats.quality.normal"));
expect(render("future-limit")).toContain(t("en", "stats.quality.unclassified"));
expect(render("future-limit")).not.toContain(t("en", "stats.quality.normal"));
});
});