import { afterEach, describe, expect, it, vi } from "vitest"; import { appendCombatEvent, MAX_COMBAT_EVENT_HISTORY } from "./combatEvents"; import { PLAYER_AURA_ENTITY_ID, useCombatStore, type MobCombatState } from "./combatStore"; import { RaceCombatRecorder } from "./dungeonRaceCombatLog"; function mob(id: string, dead = false, diedAt: number | null = null): MobCombatState { return { id, name: id, boss: id === "boss", maxHealth: 1_000, engaged: true, dead, diedAt, despawned: false } as MobCombatState; } describe("race combat recording", () => { afterEach(() => { vi.useRealTimers(); useCombatStore.setState({ mobs: {} }); }); it("keeps earlier events beyond the HUD ring and times kills and overlapping packs", () => { vi.useFakeTimers(); vi.setSystemTime(1_000); useCombatStore.setState({ mobs: {} }); const recorder = new RaceCombatRecorder("race-test", "bite-sized-test"); try { vi.setSystemTime(1_200); useCombatStore.setState({ mobs: { first: mob("first"), boss: mob("boss") } }); let hudHistory = [] as ReturnType; for (let id = 1; id <= MAX_COMBAT_EVENT_HISTORY + 75; id += 1) { hudHistory = appendCombatEvent(hudHistory, { occurredAt: 1_200 + id, kind: "damage", sourceActorId: PLAYER_AURA_ENTITY_ID, targetActorId: id % 2 ? "first" : "boss", abilityId: "test-aoe", rawAmount: 2, effectiveAmount: 2, overheal: 0, absorbed: 0, critical: false }, id); } vi.setSystemTime(2_000); useCombatStore.setState({ mobs: { first: mob("first", true, 2_000), boss: mob("boss", true, 2_000) } }); const log = recorder.finish(1_000, 2_000); expect(hudHistory).toHaveLength(MAX_COMBAT_EVENT_HISTORY); expect(log.events).toHaveLength(MAX_COMBAT_EVENT_HISTORY + 75); expect(log.droppedEventCount).toBe(0); expect(log.kills).toHaveLength(2); expect(log.kills.every((kill) => kill.firstDamageAtMs !== null && kill.durationMs < 800)).toBe(true); expect(log.packs).toHaveLength(1); expect(log.packs[0].mobIds).toEqual(["first", "boss"]); expect(log.packs[0].partyDamage.find((entry) => entry.actorId === PLAYER_AURA_ENTITY_ID)?.damage) .toBe((MAX_COMBAT_EVENT_HISTORY + 75) * 2); } finally { recorder.stop(); } }); });