Files
JoshHeaps.Net/tests/holdem/load.js
T
jheapsandClaude Opus 5 6992833821 Make the way back reachable, and stop it leaving while it is being reached for
This tool prefers undo to confirmation, deliberately — runUndoable says so in
as many words — which makes the toast's Undo the safety net under the biggest
things it does. It was not one.

Every whole-step undo clears the per-action history on its way past, so the
bar has no pill left and the toast's button is the only way back. Measured on
a desktop it is the 67th of the page's 68 tab stops, and it is gone in eight
seconds. And U — the key the sidebar legend advertises as taking back the
last action — found nothing and did nothing: it only ever looked in the bar.
So U looks at the toast first, by pressing the button that is on the screen
rather than running a second copy of what it does, and only at a button that
named the shortcut: "Turn off" on the wake lock and "Reload" on the other-tab
warning are not things a stray keypress should reach.

The eight seconds also ran whatever the dealer was doing. A cursor resting on
the toast did not stop it; nor did tabbing onto the button. Measured before:
focus the Undo, wait 8.6 seconds, and the toast is gone and focus has been
handed to <body> — the offer withdrawn and the dealer's place in the page
with it. Touching it or tabbing into it now stops the clock, and letting go
starts it again with at least the time to act rather than whatever was left
of the time to notice: let go at 7.9 seconds of 8 and 100ms is not an offer.
Dismissing with focus inside puts focus back where the dealer had got to,
which is read off where focus crossed into the toast rather than off where it
was when the message arrived.

And each toast carried its own role="status" inside #toastHost, which is
already a live region in the markup. A region nested in a region, announced
twice; the one in the markup is the one that works, because it is the one
anything has been watching.

1342 tests pass, 18 of them new — and 8 of those fail against the old code.
The sweep is clean across 428 audits; contrast unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015bnp7xKUPFFSpwkYNFaPgb
2026-09-15 04:59:18 -06:00

136 lines
5.1 KiB
JavaScript

// Loads the dealer's browser modules into Node so they can be tested directly.
//
// The modules are plain script-tag files: each one declares a `const` namespace and
// ends with a `module.exports` guard. In the browser they find each other as globals,
// so the same names have to exist on `globalThis` here or `Betting` can't reach
// `HoldemState`. Load order matches the <script> order in TexasHoldem.cshtml.
const path = require("path");
const SRC = path.join(__dirname, "..", "..", "JoshHeaps.Net", "wwwroot", "js", "casino", "holdem");
function load(name) {
const mod = require(path.join(SRC, `${name}.js`));
globalThis[name.charAt(0).toUpperCase() + name.slice(1)] = mod;
return mod;
}
const Money = load("money");
const HandRank = load("handRank");
const PotCalculator = load("potCalculator");
const SplitCalculator = load("splitCalculator");
const Betting = load("betting");
const SettleUp = load("settleUp");
const HandHistoryExport = load("handHistoryExport");
// render.js exports { Render } rather than the namespace directly.
const Render = require(path.join(SRC, "render.js")).Render;
globalThis.Render = Render;
// state.js exports `HoldemState`, which doesn't match its filename.
const HoldemState = require(path.join(SRC, "state.js"));
globalThis.HoldemState = HoldemState;
// actionBar.js after state, since its own module-level code reaches for neither but
// its methods reach for both. Loaded last so nothing it touches is still undefined.
const ActionBar = load("actionBar");
// The picker's slot bookkeeping — which slots it is filling, what is already dealt —
// is plain state work and testable here. Only render() and open() touch the DOM.
const CardPicker = load("cardPicker");
// The wake lock's rule about when a table needs the screen is plain state work too.
// Its acquire/release bookkeeping is testable here as well, against a stand-in for
// navigator.wakeLock — see wakeLock.test.js.
const WakeLock = load("wakeLock");
// feedback.js exports two namespaces and a third. Two of them answer here: Unavailable,
// which is nearly all logic (see theUnansweredPress), and Toast, whose timer and focus
// bookkeeping ask little enough of a document that a stand-in can answer (see
// theWayBack). All three are also set as globals, the way the browser hands them to
// render.js and cardPicker.js.
const { Toast, Dialog, Unavailable } = require(path.join(SRC, "feedback.js"));
globalThis.Toast = Toast;
globalThis.Dialog = Dialog;
globalThis.Unavailable = Unavailable;
// Modal is DOM behaviour through and through, but two pieces of it answer here: the
// list of what counts as a Tab stop, which is a string, and preservingFocus, which asks
// so little of a document that a stand-in can answer it. See theKeyboardInASheet.
const Modal = load("modal");
// Quick Split draws itself entirely from the DOM, but the arithmetic that decides what
// its two steppers are allowed to reach — and how many ways a pot may be chopped — is
// plain and answers here. See theWaysControl.
const QuickSplit = load("quickSplit");
// The seat menu's list — which actions a seat is offered and which group each one
// lands in — is decided before anything is drawn, so actionsFor() answers here. Only
// render() and open() touch the DOM.
const SeatMenu = load("seatMenu");
// ---- Table builders ----------------------------------------------------------
// A table with `seatCount` chairs where `seated` (a list of seat indexes) are dealt
// in with `stack` chips each. Everything else is the app's own defaults, so a test
// that forgets to set a field gets whatever a real dealer would get.
function makeTable({ seatCount = 6, seated = null, stack = 100, smallBlind = 1, bigBlind = 2, dealerSeatIndex = 0 } = {}) {
const state = HoldemState.createDefault();
HoldemState.resizeSeats(state, seatCount);
state.smallBlind = smallBlind;
state.bigBlind = bigBlind;
state.dealerSeatIndex = dealerSeatIndex;
const sitting = seated || state.seats.map((_, i) => i);
state.seats.forEach((player, index) => {
player.inHand = sitting.includes(index);
player.stack = sitting.includes(index) ? stack : null;
player.name = `P${index + 1}`;
});
return state;
}
// Total chips the table is accountable for: what's in front of everyone, plus what
// they've pushed in this street, plus what's already banked into the pot.
function chipsOnTable(state) {
return Money.round(
state.seats.reduce(
(sum, p) => sum + (Number(p.stack) || 0) + (Number(p.committed) || 0) + (Number(p.amountOverride) || 0),
0
)
);
}
// Contributions in the shape PotCalculator wants them.
function contributions(state) {
return state.seats
.filter(p => p.inHand)
.map(p => ({
id: p.id,
contribution: Betting.handTotal(p),
folded: p.folded,
}));
}
module.exports = {
Money,
HandRank,
Render,
HandHistoryExport,
PotCalculator,
SplitCalculator,
SettleUp,
Betting,
HoldemState,
ActionBar,
CardPicker,
WakeLock,
SeatMenu,
Modal,
QuickSplit,
Toast,
Unavailable,
makeTable,
chipsOnTable,
contributions,
};