Files
Dune/tests/kull-richese-revival-table-controls.test.tsx
T
Quintine 4dfdd500e0
Verify and publish checkpoint container / container (push) Successful in 10m31s
Support Revival answers with Richese Semuta
2026-10-29 01:12:37 +11:00

92 lines
5.0 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { registerHooks } from 'node:module';
import { readFileSync } from 'node:fs';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { handLimit, viewGame, type Action, type GameView } from '../game/engine';
import { act, finishRevival, inventory, player } from './fixture-kull-revival-semuta';
import { createSemutaRevivalBenefitsForcesFixture } from './fixture-semuta-revival-benefits-forces';
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 {GameTable} = await import('../components/game-table');
const {Truthtrance} = await import('../components/truthtrance');
const {RevivalPromiseGuideButton} = await import('../components/revival-promises');
aliases.deregister();
const table = (game:GameView) => renderToStaticMarkup(createElement(GameTable,
{game,busy:false,send:async () => {},onExit() {}}));
const truth = (game:GameView) => renderToStaticMarkup(createElement(Truthtrance,
{game,busy:false,act() {}}));
/** The native Basic source actually buys Semuta, ships four CHOAM forces and
* loses them to Storm. Only an original physical Truthtrance is reassigned to
* the asker; no phase, force, purse, pending decision or promise is installed. */
void test('the Kull and Richese table renders a real Revival question, answer and owned return guide',()=>{
const source = createSemutaRevivalBenefitsForcesFixture({kind:'choamRevival',advanced:false});
let game = structuredClone(source.beforeRevival);
assert.ok(game.kullPreview && game.semutaPreview);
assert.equal(player(game,'choam').tanks,4);
const originalCards = inventory(game);
const zones = [game.deck,game.discard,...(game.richeseCache ? [game.richeseCache] : []),
...(game.richeseRemoved ? [game.richeseRemoved] : []),...game.players.map(seat=>seat.hand)];
const zone = zones.find(cards=>cards.some(card=>card.effect === 'truthtrance')); assert.ok(zone);
const [card] = zone.splice(zone.findIndex(row=>row.effect === 'truthtrance'),1);
const asker = player(game,'atreides'); assert.ok(asker.hand.length < handLimit(asker));
asker.hand.push(card);
assert.deepEqual(inventory(game),originalCards);
game = act(game,'atreides',{type:'card',card:card.id});
while (game.truthtrance?.stage === 'priority') {
const next = game.players.find(seat=>!game.truthtrance!.passed.includes(seat.id)); assert.ok(next);
game = act(game,next.id,{type:'truthPass'});
}
const asking = viewGame(game,'atreides');
assert.ok(asking.truthRevivalTargets.includes('choam'));
assert.match(truth(asking), /<option value="revival">Bind ordinary force revivals this turn<\/option>/);
assert.match(table(asking), /Bind ordinary force revivals this turn/);
game = act(game,'atreides',{type:'truthAsk',question:{kind:'revival',target:'choam',
turn:game.turn,counter:'total',minimum:3}});
const respondent = viewGame(game,'choam');
assert.ok(respondent.truthRevivalAnswers?.includes('yes'));
assert.ok(respondent.truthRevivalAnswers?.includes('no'));
assert.equal(viewGame(game,'atreides').truthRevivalAnswers,null);
assert.match(truth(respondent),/Answer Yes/);
assert.match(truth(respondent),/Answer No/);
assert.match(table(respondent),/Answer Yes/);
assert.match(table(respondent),/Answer No/);
game = act(game,'choam',{type:'truthAnswer',answer:'yes'});
const pending = game.pendingTreacheryDiscard; assert.ok(pending?.reaction);
const event = pending.batch.event;
for (let count=0;game.pendingTreacheryDiscard?.batch.event === event && count<game.players.length;count++) {
const reaction = game.pendingTreacheryDiscard!.reaction; assert.ok(reaction?.stage === 'offer');
const next = game.players.find(seat=>!reaction.passed.includes(seat.id)); assert.ok(next);
game = act(game,next.id,{type:'semutaPass',event});
}
assert.notEqual(game.pendingTreacheryDiscard?.batch.event,event);
const own = viewGame(game,'choam'), sent:Action[] = [];
assert.ok(own.revivalPromiseGuide);
assert.match(table(own),/Revive 3 forces while honoring your answers/);
const button = RevivalPromiseGuideButton({game:own,busy:false,send(action) {sent.push(action);}});
assert.ok(button); assert.equal(button.props.disabled,false); button.props.onClick();
assert.deepEqual(sent,[own.revivalPromiseGuide.action]);
game = act(game,'choam',sent[0]);
game = finishRevival(game);
assert.ok(game.revivalPromises?.some(row=>row.player === 'choam' && row.fulfilled));
assert.equal(player(game,'choam').tanks,1);
assert.deepEqual(inventory(game),originalCards);
});