import { describe, expect, test } from "bun:test"; import { roster, rosterKey } from "../static/roster.js"; const snapshot = (players: unknown[]) => ({ me: { id: "p3" }, players, }); const mate = (id: string, over: Record = {}) => ({ id, name: id.toUpperCase(), agent: "veil", hp: 100, alive: true, mate: true, spike: false, ...over, }); describe("the team roster", () => { test("is your own side, everybody, seen or not", () => { const rows = roster( snapshot([mate("p1"), mate("p2"), mate("p3"), mate("p4"), mate("p5"), mate("e1", { mate: false })]), ); expect(rows.length).toBe(5); expect(rows.some((r) => r.id === "e1")).toBe(false); }); test("keeps one order whatever order the snapshot arrives in", () => { const one = roster(snapshot([mate("p3"), mate("p1"), mate("p2")])); const two = roster(snapshot([mate("p2"), mate("p3"), mate("p1")])); expect(one.map((r) => r.id)).toEqual(two.map((r) => r.id)); expect(one.map((r) => r.id)).toEqual(["p1", "p2", "p3"]); }); test("marks the dead and gives them no health", () => { const rows = roster(snapshot([mate("p1", { alive: false, hp: 37 })])); expect(rows[0]!.alive).toBe(false); expect(rows[0]!.hp).toBe(0); }); test("clamps a health the server rounded past the ends", () => { expect(roster(snapshot([mate("p1", { hp: 140 })]))[0]!.hp).toBe(100); expect(roster(snapshot([mate("p1", { hp: -5 })]))[0]!.hp).toBe(0); }); test("knows which row is you, and who has the spike", () => { const rows = roster(snapshot([mate("p1"), mate("p3", { spike: true })])); expect(rows.find((r) => r.id === "p3")!.mine).toBe(true); expect(rows.find((r) => r.id === "p3")!.spike).toBe(true); expect(rows.find((r) => r.id === "p1")!.mine).toBe(false); }); test("no snapshot is no rows, not a crash", () => { expect(roster(null)).toEqual([]); }); test("the key changes when anything on the panel changes, and not otherwise", () => { const before = roster(snapshot([mate("p1", { hp: 80 })])); expect(rosterKey(before)).toBe(rosterKey(roster(snapshot([mate("p1", { hp: 80 })])))); expect(rosterKey(before)).not.toBe(rosterKey(roster(snapshot([mate("p1", { hp: 40 })])))); expect(rosterKey(before)).not.toBe(rosterKey(roster(snapshot([mate("p1", { hp: 80, alive: false })])))); }); });