import { describe, expect, test } from "bun:test"; import { choosePrompt } from "../static/prompt.js"; type Snap = ReturnType; const snapshot = (over: Record = {}, me: Record = {}, spike: Record = {}) => ({ phase: "live", clock: 40, result: null, me: { side: "atk", alive: true, blind: 0, planting: 0, spike: false, ...me }, spike: { planted: false, carried: false, fuse: 0, defuse: 0, x: 100, y: 100, ...spike }, ...over, }); describe("the one prompt on screen", () => { test("the buy phase says what to do and how long there is", () => { const text = choosePrompt(snapshot({ phase: "buy", clock: 14.2 })); expect(text).toBe("Buy phase — 15s left. Click a gun you can afford."); }); test("carrying the spike off a site sends you to one", () => { expect(choosePrompt(snapshot({}, { spike: true }), { onSite: false })).toBe( "You have the spike — get to site A or B", ); }); test("carrying it onto a site says how to plant", () => { expect(choosePrompt(snapshot({}, { spike: true }), { onSite: true })).toBe("Hold F to plant"); }); test("a defender near a planted spike is told to defuse, with the fuse", () => { const text = choosePrompt(snapshot({}, { side: "def" }, { planted: true, fuse: 31.4 }), { nearSpike: true }); expect(text).toBe("Spike down, 32s — hold F to defuse"); }); test("a defender across the map is told to get to it", () => { const text = choosePrompt(snapshot({}, { side: "def" }, { planted: true, fuse: 31.4 }), { nearSpike: false }); expect(text).toBe("Spike down, 32s — get to it and hold F"); }); test("an attacker with it planted is told to hold the site", () => { expect(choosePrompt(snapshot({}, {}, { planted: true, fuse: 10 }))).toBe( "Spike down, 10s — keep them off it", ); }); test("blind beats everything else on screen", () => { const text = choosePrompt(snapshot({}, { blind: 1.4, spike: true }), { onSite: true }); expect(text).toBe("You are blind — back off until it clears"); }); test("dead in a live round says you are still in the match", () => { expect(choosePrompt(snapshot({}, { alive: false }))).toBe("Waiting for the next round — you're in it"); }); test("the end of a round shows the result and the countdown", () => { const text = choosePrompt(snapshot({ phase: "end", clock: 4.1, result: "Spike defused" })); expect(text).toBe("Spike defused — next round in 5s"); }); test("a live defender is told what defending is", () => { expect(choosePrompt(snapshot({}, { side: "def" }))).toBe("Defending — hold A and B, 40s"); }); test("an attacker beside a loose spike is told to walk onto it", () => { expect(choosePrompt(snapshot(), { nearSpike: true })).toBe("Walk onto the spike to pick it up"); }); test("defusing counts down the defuse, not the fuse", () => { const text = choosePrompt(snapshot({}, { side: "def" }, { planted: true, fuse: 20, defuse: 3.5 }), { nearSpike: true, }); expect(text).toBe("Defusing — keep holding F, 4s"); }); test("no snapshot yet is no prompt", () => { expect(choosePrompt(null as unknown as Snap)).toBe(""); }); });