import { describe, expect, test } from "vitest"; import { samThreatensNukePreview, shouldPreserveGhostAfterBuild, } from "../../../src/client/controllers/BuildPreviewController"; import { UnitType } from "../../../src/core/game/Game"; describe("BuildPreviewController ghost preservation (locked nuke / Enter confirm)", () => { describe("shouldPreserveGhostAfterBuild", () => { test("returns true for AtomBomb so ghost is not cleared after placement", () => { expect(shouldPreserveGhostAfterBuild(UnitType.AtomBomb)).toBe(true); }); test("returns true for HydrogenBomb so ghost is not cleared after placement", () => { expect(shouldPreserveGhostAfterBuild(UnitType.HydrogenBomb)).toBe(true); }); test("returns false for City so ghost is cleared after placement", () => { expect(shouldPreserveGhostAfterBuild(UnitType.City)).toBe(false); }); test("returns false for Factory so ghost is cleared after placement", () => { expect(shouldPreserveGhostAfterBuild(UnitType.Factory)).toBe(false); }); test("returns false for other buildable types (Port, DefensePost, MissileSilo, SAMLauncher, Warship, MIRV)", () => { expect(shouldPreserveGhostAfterBuild(UnitType.Port)).toBe(false); expect(shouldPreserveGhostAfterBuild(UnitType.DefensePost)).toBe(false); expect(shouldPreserveGhostAfterBuild(UnitType.MissileSilo)).toBe(false); expect(shouldPreserveGhostAfterBuild(UnitType.SAMLauncher)).toBe(false); expect(shouldPreserveGhostAfterBuild(UnitType.Warship)).toBe(false); expect(shouldPreserveGhostAfterBuild(UnitType.MIRV)).toBe(false); }); }); }); describe("samThreatensNukePreview (nuke trajectory threat set, #4226)", () => { const allies = new Set([2, 3]); test("non-allied SAM threatens the trajectory", () => { expect(samThreatensNukePreview(5, allies, new Set())).toBe(true); }); test("allied SAM does not threaten when the strike breaks no alliance", () => { expect(samThreatensNukePreview(2, allies, new Set())).toBe(false); }); test("would-be-betrayed ally's SAM threatens (alliance breaks at launch)", () => { expect(samThreatensNukePreview(2, allies, new Set([2]))).toBe(true); }); test("other allies' SAMs still excluded when a different ally is betrayed", () => { expect(samThreatensNukePreview(3, allies, new Set([2]))).toBe(false); }); });