Files
healer-man/src/game/threatMeter.test.ts
T
2026-08-14 15:56:39 -04:00

46 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { threatMeterRows, type ThreatMeterActor } from "./threatMeter";
const actors: readonly ThreatMeterActor[] = [
{ id: "__player__", name: "Player", role: "healer", alive: true },
{ id: "tank", name: "Tank", role: "tank", alive: true },
{ id: "dps-a", name: "DPS A", role: "damage", alive: true },
{ id: "downed", name: "Downed", role: "damage", alive: false },
];
describe("threat meter rows", () => {
it("ranks living known actors and normalizes the leader to one hundred percent", () => {
expect(threatMeterRows(
{ "__player__": 25, tank: 100, "dps-a": 50, downed: 999, stale: 500 },
actors,
"dps-a",
null,
1_000,
)).toEqual([
expect.objectContaining({ actorId: "tank", percentOfLeader: 100, currentTarget: false }),
expect.objectContaining({ actorId: "dps-a", percentOfLeader: 50, currentTarget: true }),
expect.objectContaining({ actorId: "__player__", percentOfLeader: 25 }),
]);
});
it("marks only an active forced target and limits the result", () => {
const rows = threatMeterRows(
{ "__player__": 25, tank: 100, "dps-a": 50 },
actors,
"tank",
{ actorId: "tank", endsAt: 2_000 },
1_999,
2,
);
expect(rows).toHaveLength(2);
expect(rows[0]).toMatchObject({ actorId: "tank", forced: true });
expect(threatMeterRows(
{ tank: 100 },
actors,
"tank",
{ actorId: "tank", endsAt: 2_000 },
2_000,
)[0].forced).toBe(false);
});
});