Files
healer-man/src/game/companionCooldownPolicy.test.ts
T
2026-09-19 21:01:51 -04:00

47 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
DEFAULT_COMPANION_COOLDOWN_POLICY,
imminentCooldownMechanic,
normalizeCompanionCooldownPolicy,
} from "./companionCooldownPolicy";
const policy = normalizeCompanionCooldownPolicy({
...DEFAULT_COMPANION_COOLDOWN_POLICY,
mechanics: [{
id: "tank-buster", enabled: true, bossKey: "test/boss", bossName: "Test Boss",
bossServerEntry: 123, attackId: "heavy-strike", attackName: "Heavy Strike",
scope: "tank", leadTimeMs: 2_500, minimumCooldownSeconds: 20,
}],
});
describe("companion cooldown policy", () => {
it("matches configured cooldown windows only for the selected boss and role", () => {
const mob = { serverEntry: 123, abilityReadyAt: { "heavy-strike": 3_000 } };
expect(imminentCooldownMechanic(mob, "tank", 1_000, policy)?.id).toBe("tank-buster");
expect(imminentCooldownMechanic(mob, "damage", 1_000, policy)).toBeNull();
expect(imminentCooldownMechanic({ ...mob, serverEntry: 456 }, "tank", 1_000, policy)).toBeNull();
expect(imminentCooldownMechanic(mob, "tank", 6_000, policy)).toBeNull();
});
it("matches an active cast inside the configured lead time", () => {
expect(imminentCooldownMechanic({
serverEntry: 123,
activeCast: { attackId: "heavy-strike", completesAt: 3_000 },
}, "tank", 1_000, policy)?.attackName).toBe("Heavy Strike");
});
it("uses the authored boss name when an encounter has no server entry", () => {
const namePolicy = normalizeCompanionCooldownPolicy({
...DEFAULT_COMPANION_COOLDOWN_POLICY,
mechanics: [{
id: "name-only", enabled: true, bossKey: "test/name-only", bossName: "Named Boss",
bossServerEntry: null, attackId: "heavy-strike", attackName: "Heavy Strike",
scope: "party", leadTimeMs: 2_500, minimumCooldownSeconds: 20,
}],
});
const window = { name: "Named Boss", abilityReadyAt: { "heavy-strike": 3_000 } };
expect(imminentCooldownMechanic(window, "healer", 1_000, namePolicy)?.id).toBe("name-only");
expect(imminentCooldownMechanic({ ...window, name: "Other Boss" }, "healer", 1_000, namePolicy)).toBeNull();
});
});