import { describe, expect, it } from "vitest"; import type { CameraProfile } from "@/lib/camera"; import { codecLabel, deviceLine, displayBrand, mainStream, streamSummary } from "./camera-summary"; const main: CameraProfile = { token: "p1", name: "mainStream", encoding: "H264", width: 4096, height: 1860, fps: 20 }; const sub: CameraProfile = { token: "p2", name: "subStream", encoding: "H264", width: 1200, height: 536, fps: 20 }; describe("mainStream", () => { it("picks the highest resolution regardless of order", () => { expect(mainStream([sub, main])).toBe(main); expect(mainStream([main, sub])).toBe(main); }); it("keeps the first on a tie, and treats missing sizes as 0", () => { const twin = { ...main, token: "p3" }; expect(mainStream([main, twin])).toBe(main); const bare = { token: "b" }; expect(mainStream([bare, sub])).toBe(sub); expect(mainStream([bare])).toBe(bare); }); it("is undefined with no profiles", () => { expect(mainStream([])).toBeUndefined(); }); }); describe("streamSummary", () => { it("describes the main stream of the probed cameras", () => { expect(streamSummary([main, sub])).toBe("Main 4096×1860 · H.264 · 20 fps"); }); it("omits missing parts", () => { expect(streamSummary([{ token: "x", encoding: "H265" }])).toBe("Main · H.265"); expect(streamSummary([{ token: "x", width: 640, height: 480 }])).toBe("Main 640×480"); expect(streamSummary([{ token: "x" }])).toBe("Main"); }); it("is null with no profiles", () => { expect(streamSummary([])).toBeNull(); }); }); describe("codecLabel", () => { it.each([ ["H264", "H.264"], ["h265", "H.265"], ["JPEG", "JPEG"], ["MPEG4", "MPEG4"], ])("%s → %s", (encoding, label) => { expect(codecLabel(encoding)).toBe(label); }); }); describe("displayBrand", () => { it.each([ ["ONVIF", undefined], ["onvif ", undefined], ["", undefined], [" ", undefined], [undefined, undefined], ["Hikvision", "Hikvision"], [" Annke ", "Annke"], ])("%j → %j", (manufacturer, brand) => { expect(displayBrand(manufacturer)).toBe(brand); }); }); describe("deviceLine", () => { it("hides the ONVIF placeholder brand", () => { expect(deviceLine({ manufacturer: "ONVIF", model: "I91ET", firmwareVersion: "V5.8.10" })).toBe( "I91ET · fw V5.8.10", ); }); it("keeps a real brand", () => { expect(deviceLine({ manufacturer: "Hikvision", model: "DS-2CD", firmwareVersion: "V5.7" })).toBe( "Hikvision DS-2CD · fw V5.7", ); }); it("omits missing parts", () => { expect(deviceLine({ model: "I91ET" })).toBe("I91ET"); expect(deviceLine({ firmwareVersion: "V1" })).toBe("fw V1"); expect(deviceLine({ manufacturer: "Annke" })).toBe("Annke"); }); it("is null when nothing is known", () => { expect(deviceLine({})).toBeNull(); expect(deviceLine({ manufacturer: "ONVIF" })).toBeNull(); }); });