import { describe, expect, it } from "vitest"; import { abilityById } from "./abilityCatalog"; import { DEFAULT_COMBAT_PRESENTATION_SETTINGS, combatEffectManifestEntry, combatEffectStyle, combatPresentationSessionId, emitCombatPresentation, normalizeCombatPresentationSettings, presentationDeliveryForAbility, presentationSchoolForAbility, resetCombatPresentationSession, subscribeCombatPresentation, type CombatPresentationMessage, } from "./combatPresentation"; describe("combat presentation", () => { it("normalizes owner settings without leaking partial or invalid values", () => { expect(normalizeCombatPresentationSettings({ vfxQuality: "low", vfxEnabled: { player: false }, audioEnabled: { enemy: false }, audioVolume: { player: 2, party: -1, enemy: 0.35 }, })).toEqual({ vfxQuality: "low", vfxEnabled: { player: false, party: true, enemy: true }, audioEnabled: { player: true, party: true, enemy: false }, audioVolume: { player: 1, party: 0, enemy: 0.35 }, }); expect(normalizeCombatPresentationSettings(null)).toEqual(DEFAULT_COMBAT_PRESENTATION_SETTINGS); }); it("delivers immutable, exactly-once events and a session reset", () => { const messages: CombatPresentationMessage[] = []; const unsubscribe = subscribeCombatPresentation((message) => messages.push(message)); const origin = [1, 2, 3] as [number, number, number]; const event = emitCombatPresentation({ occurredAt: 1_000, phase: "release", actorGroup: "player", sourceActorId: "player", targetActorId: "mob", abilityId: "fixture", sourceSpellId: 116, name: "Frostbolt", source: "wow335", school: "frost", delivery: "projectile", origin, targetPosition: [8, 0, 0], }); origin[0] = 99; const nextSession = resetCombatPresentationSession(); unsubscribe(); expect(messages).toHaveLength(2); expect(messages[0]).toEqual({ kind: "event", event }); expect(event.origin).toEqual([1, 2, 3]); expect(messages[1]).toEqual({ kind: "reset", sessionId: nextSession }); expect(combatPresentationSessionId()).toBe(nextSession); }); it("uses authentic source descriptors and school/delivery fallbacks", () => { const frostbolt = abilityById("mage-frostbolt"); expect(frostbolt).not.toBeNull(); expect(presentationSchoolForAbility(frostbolt!)).toBe("frost"); expect(presentationDeliveryForAbility(frostbolt!)).toBe("projectile"); expect(combatEffectManifestEntry(999_999, "wow335")).toBeNull(); const style = combatEffectStyle({ id: 1, sessionId: 1, occurredAt: 1, phase: "release", actorGroup: "player", sourceActorId: "player", abilityId: "mage-frostbolt", sourceSpellId: 999_999, name: "Frostbolt", source: "wow335", school: "frost", delivery: "projectile", origin: [0, 0, 0], }); expect(style.authentic).toBe(false); expect(style.sourceModelNames).toEqual([]); }); });