Files
Dune/tests/basic-early-leaderless-dead-controls.test.tsx
Quintine e439f3f7b6
Verify and publish checkpoint container / container (push) Canceled after 0s
Add dead leader battle preparation
2026-10-29 08:42:28 +11:00

59 lines
2.8 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { readFileSync } from 'node:fs';
import { registerHooks } from 'node:module';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import type { GameView } from '../game/engine';
const aliases = registerHooks({
resolve(specifier, context, next) {
return next(specifier === 'next/image' ? 'vinext/shims/image' :
specifier === 'next/link' ? 'vinext/shims/link' : specifier, context);
},
load(url, context, next) {
if (!url.endsWith('.module.css')) return next(url, context);
const css = readFileSync(new URL(url), 'utf8');
const classes = Object.fromEntries([...css.matchAll(/\.([a-zA-Z_][\w-]*)/g)].map(match => [match[1], match[1]]));
return {format:'module', source:`export default ${JSON.stringify(classes)}`, shortCircuit:true};
},
});
const { BattleLeaderOpportunity } = await import('../components/residual-poison');
aliases.deregister();
/** This component consumes only public readiness, roster and interaction state. */
function view(options: {richese?: boolean; ready?: boolean; interrupted?: boolean} = {}) {
return {
me:'a', players:[{id:'a',name:'Atreides',faction:'atreides'},
{id:'g',name:'Guild',faction:'guild'},
...(options.richese ? [{id:'r',name:'Richese',faction:'richese'}] : [])],
battle:{attacker:'a',defender:'g',preLeader:{event:'battle',ready:options.ready ? ['a'] : [],closed:false}},
response:options.interrupted ? {kind:'voice'} : null,
truthtrance:null, decision:null, phaseOpening:null,
} as unknown as GameView;
}
const render = (game:GameView, busy = false) => renderToStaticMarkup(
createElement(BattleLeaderOpportunity, {game,busy,act() { assert.fail('Rendering must not act.'); }}),
);
void test('the neutral pre-leader opportunity explains Ghola without claiming a player holds it', () => {
const html = render(view());
assert.match(html, /use a held Ghola from your hand to revive an eligible leader/);
assert.match(html, /Ready to choose leaders/);
assert.doesNotMatch(html, /Juice of Sapho/);
assert.doesNotMatch(html, /You hold|has a Ghola/);
});
void test('Sapho guidance appears only when Richese is seated', () => {
assert.match(render(view({richese:true})), /A held Juice of Sapho can make you aggressor/);
assert.doesNotMatch(render(view()), /Juice of Sapho/);
});
void test('ready, busy and interrupted states retain the existing shared-stage controls', () => {
assert.match(render(view({ready:true})), /You are ready\. Waiting for the other combatant/);
assert.match(render(view(), true), /<button[^>]*disabled=""/);
const interrupted = render(view({interrupted:true}));
assert.match(interrupted, /Resolve the current interaction before continuing/);
assert.match(interrupted, /<button[^>]*disabled=""/);
});