Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334import { describe, expect, it } from "vitest";import { CASES } from "../../tools/panelCases";import { shuffled } from "../../tools/panelKit";
describe("the cold-reader panel's cases (P4-7)", () => { it("nine cases: three where the app is broken, three where the script is out of date, three that cannot be told", () => { expect(CASES).toHaveLength(9); for (const truth of ["app-broken", "script-out-of-date", "ambiguous"]) expect(CASES.filter((c) => c.truth === truth), truth).toHaveLength(3); }); it("every case has an id of its own, a reason for its truth, two different pages and steps that check something", () => { expect(new Set(CASES.map((c) => c.id)).size).toBe(CASES.length); for (const c of CASES) { expect(c.why.length, c.id).toBeGreaterThan(30); expect(c.a, c.id).not.toBe(c.b); expect(c.steps, c.id).toContain("verify"); expect(c.steps, c.id).toMatch(/step "/); } }); it("nothing a reader can see gives the answer away: pages and steps never use the words of the verdicts or the case ids", () => { // ids that are also ordinary words a page may need (balance, error, menu, gone, pending) cannot be searched for; the others must not appear at all const ids = ["typo", "restyled-link", "heading-reworded", "capitals"]; expect(ids.every((id) => CASES.some((c) => c.id === id))).toBe(true); const giveaways = [/app[- ]broken/i, /script[- ]out/i, /out of date/i, ...ids.map((id) => new RegExp(id, "i"))]; for (const c of CASES) for (const text of [c.a, c.b, c.steps]) for (const g of giveaways) expect(text, `${c.id}: ${g}`).not.toMatch(g); }); it("shuffled is a permutation, the same for the same seed, and different for another", () => { const items = [1, 2, 3, 4, 5, 6, 7, 8, 9]; expect(shuffled(items, 1).sort()).toEqual(items); expect(shuffled(items, 7)).toEqual(shuffled(items, 7)); expect(shuffled(items, 7)).not.toEqual(shuffled(items, 8)); expect(items).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]); });});