82 lines
4.7 KiB
TypeScript
82 lines
4.7 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 Game, type GameView } from '../game/engine';
|
|
import { beforeIxSpiceDraw, orderIxSpiceCards } from './fixture-ix-spice-cards';
|
|
import { act, advance, clean, createKullRicheseSemutaFixture, inventory, player } from './fixture-kull-richese-semuta';
|
|
|
|
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 { AlliancePromiseGuideButton } = await import('../components/alliance-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 game purchases Semuta through Richese's real cache auction.
|
|
* Only a physical Truthtrance is reassigned and an unopened Worm and replacement
|
|
* are selected; the offer, question, Semuta pass and acceptance are real actions. */
|
|
function source() {
|
|
const f = createKullRicheseSemutaFixture();
|
|
let game = structuredClone(f.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,'harkonnen'); assert.ok(asker.hand.length < handLimit(asker)); asker.hand.push(card);
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
game = advance(game,state => state.turn === 2 && beforeIxSpiceDraw(state));
|
|
orderIxSpiceCards(game,['worm','land']);
|
|
game = advance(game,state => state.phase === 1 && state.nexus && clean(state) && !state.spiceWindow && !state.spiceResolution);
|
|
game = act(game,'richese',{type:'alliance',target:'emperor'});
|
|
game = act(game,'harkonnen',{type:'card',card:card.id});
|
|
while (game.truthtrance?.stage === 'priority') {
|
|
const seat = game.players.find(row => !game.truthtrance!.passed.includes(row.id)); assert.ok(seat);
|
|
game = act(game,seat.id,{type:'truthPass'});
|
|
}
|
|
return {game,originalCards:f.originalCards};
|
|
}
|
|
|
|
void test('Basic Kull and Richese render a genuine alliance question and owned acceptance guide',()=>{
|
|
const f = source(); let game:Game = f.game;
|
|
const asker = viewGame(game,'harkonnen');
|
|
assert.ok(asker.truthAllianceTargets.includes('emperor'));
|
|
assert.match(truth(asker), /<option value="alliance">Bind alliance membership at this Nexus close<\/option>/);
|
|
assert.match(table(asker), /Bind alliance membership at this Nexus close/);
|
|
game = act(game,'harkonnen',{type:'truthAsk',question:{kind:'alliance',target:'emperor',turn:game.turn,partner:'richese'}});
|
|
const respondent = viewGame(game,'emperor');
|
|
assert.ok(respondent.truthAllianceAnswers?.includes('yes'));
|
|
assert.ok(respondent.truthAllianceAnswers?.includes('no'));
|
|
assert.equal(viewGame(game,'harkonnen').truthAllianceAnswers,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,'emperor',{type:'truthAnswer',answer:'yes'});
|
|
game = advance(game,clean);
|
|
const own = viewGame(game,'emperor'), sent:Action[] = [];
|
|
assert.ok(own.alliancePromiseGuide);
|
|
assert.match(table(own),/Accept richese.*alliance invitation/);
|
|
const button = AlliancePromiseGuideButton({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.alliancePromiseGuide.action]);
|
|
game = act(game,'emperor',sent[0]);
|
|
assert.equal(player(game,'emperor').ally,'richese');
|
|
assert.deepEqual(inventory(game),f.originalCards);
|
|
});
|