// The legend and the key map must not drift apart. // // F, C and R are printed on the buttons they drive. A and U were on nothing at all, // so a dealer who learned the first three from the action bar had no way to find out // the other two existed. The guard against that happening again is this file. const test = require("node:test"); const assert = require("node:assert"); const path = require("path"); const Shortcuts = require(path.join( __dirname, "..", "..", "JoshHeaps.Net", "wwwroot", "js", "casino", "holdem", "shortcuts.js")); test("every shortcut has a line in the legend", () => { const documented = new Set(Shortcuts.LEGEND.map(entry => entry.action)); const missing = [...new Set(Object.values(Shortcuts.KEYS))].filter(action => !documented.has(action)); assert.deepEqual(missing, [], "a shortcut with no legend line is one nobody can find"); }); test("the legend doesn't describe shortcuts that don't exist", () => { const real = new Set(Object.values(Shortcuts.KEYS)); const invented = Shortcuts.LEGEND.map(entry => entry.action).filter(action => !real.has(action)); assert.deepEqual(invented, []); }); test("every legend line names its keys and says what they do", () => { Shortcuts.LEGEND.forEach(entry => { assert.ok(Array.isArray(entry.keys) && entry.keys.length > 0, `${entry.action} has no keys`); assert.ok(entry.keys.every(key => typeof key === "string" && key.trim()), `${entry.action} has a blank key`); assert.ok(entry.what && entry.what.trim().length > 3, `${entry.action} has no description`); }); }); test("the keys named match the keys bound", () => { // "Space" and "Enter" both drive advance; the map holds them as " " and "enter". const spoken = { space: " ", enter: "enter", esc: "escape" }; Shortcuts.LEGEND.forEach(entry => { entry.keys.forEach(label => { const key = spoken[label.toLowerCase()] || label.toLowerCase(); assert.equal(Shortcuts.KEYS[key], entry.action, `the legend says ${label} is ${entry.action}, the map disagrees`); }); }); }); test("no two lines claim the same key", () => { const seen = new Set(); Shortcuts.LEGEND.forEach(entry => entry.keys.forEach(key => { assert.ok(!seen.has(key.toLowerCase()), `${key} is listed twice`); seen.add(key.toLowerCase()); })); });