Compose phase-wide and ordinary bid commitments
Verify and publish checkpoint container / container (push) Successful in 10m37s
Verify and publish checkpoint container / container (push) Successful in 10m37s
This commit is contained in:
1 parent
9e020ccd64
commit
1ff520a9fc
11 files changed
+591
-15
No files matched your search
@@ -0,0 +1,82 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createElement } from 'react';
|
||||
import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import { BidPromiseGuideButton, BidPromises } from '../components/bid-promises';
|
||||
import { MixedBidPromises } from '../components/mixed-bid-promises';
|
||||
import { PhaseAnyBidGuideButton, PhaseAnyBidPromises } from '../components/phase-any-bid-promises';
|
||||
import { viewGame, type Action, type Game } from '../game/engine';
|
||||
import { actTruthBid as act, createTruthBidFixture, truthBidInventory as inventory,
|
||||
type TruthBidFixture } from './fixture-truth-bid';
|
||||
|
||||
function answer(game:Game,f:TruthBidFixture,card:string,question:Record<string,unknown>) {
|
||||
let state=act(game,f.asker,{type:'card',card});
|
||||
for (let n=0;state.truthtrance?.stage === 'priority' && n<state.players.length;n++) {
|
||||
const actor=state.players.find(row => !state.truthtrance!.passed.includes(row.id)); assert.ok(actor);
|
||||
state=act(state,actor.id,{type:'truthPass'});
|
||||
}
|
||||
assert.equal(state.truthtrance?.stage,'ask');
|
||||
state=act(state,f.asker,{type:'truthAsk',question});
|
||||
return act(state,f.target,{type:'truthAnswer',answer:'yes'});
|
||||
}
|
||||
|
||||
/** Real public-start game with native cards and bids. The shared fixture selects
|
||||
* unopened deal, auction and Spice order and scalar rolls without inventing
|
||||
* cards, money, bids or answers. */
|
||||
function joint(advanced:boolean,kind:'bid'|'mixedBid') {
|
||||
const f=createTruthBidFixture({advanced,window:'active'});
|
||||
const phase={kind:'phaseAnyBid',target:f.target,turn:f.game.turn,minimum:4};
|
||||
const lot=kind === 'bid' ? {kind,target:f.target,turn:f.game.turn,lot:1,minimum:6} :
|
||||
{kind,target:f.target,turn:f.game.turn,lot:1,mixed:{kind:'and',terms:[
|
||||
{kind:'fact',fact:{kind:'spice',compare:'gte',value:10}},
|
||||
{kind:'action',action:{minimum:6}},
|
||||
]}};
|
||||
let game=answer(f.game,f,f.truths[0],phase);
|
||||
game=answer(game,f,f.truths[1],lot);
|
||||
return {game,f};
|
||||
}
|
||||
|
||||
for (const advanced of [false,true]) for (const kind of ['bid','mixedBid'] as const) void test(
|
||||
`${advanced?'Advanced':'Basic'} ${kind} and any-auction controls share a live dual-tagged action`,() => {
|
||||
const {game,f}=joint(advanced,kind), view=viewGame(game,f.target), sent:Action[]=[];
|
||||
assert.ok(view.phaseAnyBidGuide && view.bidPromiseGuide);
|
||||
const action=view.phaseAnyBidGuide.action;
|
||||
assert.deepEqual(action,view.bidPromiseGuide.action);
|
||||
assert.equal(action.type,'bid'); assert.equal(action.amount,6);
|
||||
assert.equal(action.phaseAnyBidPromiseEvent,game.phaseAnyBidPromises?.find(row => row.player === f.target)?.event);
|
||||
assert.equal(action.bidPromiseEvent,game.bidPromises?.find(row => row.player === f.target)?.event);
|
||||
assert.equal(action.phaseAnyBidLot,1);
|
||||
const props={game:view,busy:false,send(value:Action){sent.push(value);}};
|
||||
const phaseHtml=renderToStaticMarkup(createElement(PhaseAnyBidPromises,props));
|
||||
const localHtml=renderToStaticMarkup(createElement(kind === 'bid' ? BidPromises : MixedBidPromises,props));
|
||||
assert.match(phaseHtml,/Your any-auction bid promises/);
|
||||
assert.match(phaseHtml,/data-testid="phase-any-bid-guide"/);
|
||||
assert.match(localHtml,kind === 'bid' ? /Your bid promises/ : /Your mixed bid promises/);
|
||||
assert.match(localHtml,/data-testid="bid-promise-guide"/);
|
||||
const phaseButton=PhaseAnyBidGuideButton(props), localButton=BidPromiseGuideButton(props);
|
||||
assert.ok(phaseButton && localButton);
|
||||
const clickPhase=() => phaseButton.props.onClick();
|
||||
const clickLocal=() => localButton.props.onClick();
|
||||
clickPhase(); clickLocal();
|
||||
assert.deepEqual(sent,[action,action]);
|
||||
props.busy=true; clickPhase(); clickLocal();
|
||||
assert.equal(sent.length,2,'A pending action suppresses either stale callback');
|
||||
props.busy=false;
|
||||
const lotNumber=view.bidPromiseLot!.lot;
|
||||
view.bidPromiseLot!.lot=lotNumber+1; clickPhase(); clickLocal();
|
||||
assert.equal(sent.length,2,'A different ordinary lot invalidates both callbacks');
|
||||
view.bidPromiseLot!.lot=lotNumber;
|
||||
const phaseReceipt=view.phaseAnyBidPromises.find(row => row.event === action.phaseAnyBidPromiseEvent); assert.ok(phaseReceipt);
|
||||
phaseReceipt.fulfilled=true; clickPhase(); clickLocal();
|
||||
assert.equal(sent.length,2,'A closed phase receipt invalidates the local callback too');
|
||||
phaseReceipt.fulfilled=false;
|
||||
const localReceipt=(kind === 'bid' ? view.bidPromises : view.mixedBidPromises)
|
||||
.find(row => row.event === action.bidPromiseEvent); assert.ok(localReceipt);
|
||||
localReceipt.fulfilled=true; clickPhase(); clickLocal();
|
||||
assert.equal(sent.length,2,'A closed local receipt invalidates the phase callback too');
|
||||
localReceipt.fulfilled=false;
|
||||
const applied=act(game,f.target,sent[0]);
|
||||
assert.ok(applied.phaseAnyBidPromises?.some(row => row.event === action.phaseAnyBidPromiseEvent && row.fulfilled));
|
||||
assert.ok(applied.bidPromises?.some(row => row.event === action.bidPromiseEvent && row.fulfilled));
|
||||
assert.deepEqual(inventory(applied),f.originalCards);
|
||||
});
|
||||
Reference in new issue
Block a user