quill/val Public Public: anyone can read this; nobody can change it.

forked from benjivers/val

workbenchthis machine
Files b5f6bddcbc04948cd09fc3f6b819512f8c7d129c
84 lines · 3.4 KB · ~1.0k tok Raw History
1
import { describe, expect, test } from "bun:test";
2
import { choosePrompt } from "../static/prompt.js";
3
4
type Snap = ReturnType<typeof snapshot>;
5
6
const snapshot = (over: Record<string, unknown> = {}, me: Record<string, unknown> = {}, spike: Record<string, unknown> = {}) => ({
7
  phase: "live",
8
  clock: 40,
9
  result: null,
10
  me: { side: "atk", alive: true, blind: 0, planting: 0, spike: false, ...me },
11
  spike: { planted: false, carried: false, fuse: 0, defuse: 0, x: 100, y: 100, ...spike },
12
  ...over,
13
});
14
15
describe("the one prompt on screen", () => {
16
  test("the buy phase says what to do and how long there is", () => {
17
    const text = choosePrompt(snapshot({ phase: "buy", clock: 14.2 }));
18
    expect(text).toBe("Buy phase — 15s left. Click a gun you can afford.");
19
  });
20
21
  test("the terminal is told about keys, not clicks", () => {
22
    const text = choosePrompt(snapshot({ phase: "buy", clock: 14.2 }), { input: "keys" });
23
    expect(text).toBe("Buy phase — 15s left. Press b and buy a gun you can afford.");
24
  });
25
26
  test("carrying the spike off a site sends you to one", () => {
27
    expect(choosePrompt(snapshot({}, { spike: true }), { onSite: false })).toBe(
28
      "You have the spike — get to site A or B",
29
    );
30
  });
31
32
  test("carrying it onto a site says how to plant", () => {
33
    expect(choosePrompt(snapshot({}, { spike: true }), { onSite: true })).toBe("Hold F to plant");
34
  });
35
36
  test("a defender near a planted spike is told to defuse, with the fuse", () => {
37
    const text = choosePrompt(snapshot({}, { side: "def" }, { planted: true, fuse: 31.4 }), { nearSpike: true });
38
    expect(text).toBe("Spike down, 32s — hold F to defuse");
39
  });
40
41
  test("a defender across the map is told to get to it", () => {
42
    const text = choosePrompt(snapshot({}, { side: "def" }, { planted: true, fuse: 31.4 }), { nearSpike: false });
43
    expect(text).toBe("Spike down, 32s — get to it and hold F");
44
  });
45
46
  test("an attacker with it planted is told to hold the site", () => {
47
    expect(choosePrompt(snapshot({}, {}, { planted: true, fuse: 10 }))).toBe(
48
      "Spike down, 10s — keep them off it",
49
    );
50
  });
51
52
  test("blind beats everything else on screen", () => {
53
    const text = choosePrompt(snapshot({}, { blind: 1.4, spike: true }), { onSite: true });
54
    expect(text).toBe("You are blind — back off until it clears");
55
  });
56
57
  test("dead in a live round says you are still in the match", () => {
58
    expect(choosePrompt(snapshot({}, { alive: false }))).toBe("Waiting for the next round — you're in it");
59
  });
60
61
  test("the end of a round shows the result and the countdown", () => {
62
    const text = choosePrompt(snapshot({ phase: "end", clock: 4.1, result: "Spike defused" }));
63
    expect(text).toBe("Spike defused — next round in 5s");
64
  });
65
66
  test("a live defender is told what defending is", () => {
67
    expect(choosePrompt(snapshot({}, { side: "def" }))).toBe("Defending — hold A and B, 40s");
68
  });
69
70
  test("an attacker beside a loose spike is told to walk onto it", () => {
71
    expect(choosePrompt(snapshot(), { nearSpike: true })).toBe("Walk onto the spike to pick it up");
72
  });
73
74
  test("defusing counts down the defuse, not the fuse", () => {
75
    const text = choosePrompt(snapshot({}, { side: "def" }, { planted: true, fuse: 20, defuse: 3.5 }), {
76
      nearSpike: true,
77
    });
78
    expect(text).toBe("Defusing — keep holding F, 4s");
79
  });
80
81
  test("no snapshot yet is no prompt", () => {
82
    expect(choosePrompt(null as unknown as Snap)).toBe("");
83
  });
84
});
↑↓ navigate ↵ open esc close
↑↓ navigate ↵ open esc close

Keyboard shortcuts