Preserve Emperor gift opportunity before bot phase pass
Verify and publish checkpoint container / container (push) Successful in 10m48s
Verify and publish checkpoint container / container (push) Successful in 10m48s
This commit is contained in:
1 parent
021a8c3e7f
commit
0c64d320ea
10 files changed
+238
-5
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {Children, createElement, isValidElement} from 'react';
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
import {EmperorPhaseOpeningPriority} from '../components/emperor-phase-opening-priority';
|
||||
import type {Action, GameView} from '../game/engine';
|
||||
|
||||
function input() {
|
||||
const sent:Action[]=[];
|
||||
const game={emperorPhaseOpeningPriority:{event:'opening',recipient:'ally',waiting:'bot',canContinue:true},
|
||||
players:[{id:'ally',name:'Ally'}]} as unknown as Pick<GameView,'emperorPhaseOpeningPriority'|'players'>;
|
||||
return {game,busy:false,sent,act:(action:Action)=>sent.push(action)};
|
||||
}
|
||||
function button(props:ReturnType<typeof input>) {
|
||||
const panel=EmperorPhaseOpeningPriority(props);assert.ok(panel);
|
||||
const control=Children.toArray(panel.props.children).find(row=>isValidElement(row)&&row.type==='button');
|
||||
assert.ok(isValidElement<{onClick:()=>void;disabled:boolean}>(control));return control;
|
||||
}
|
||||
void test('the Emperor can continue the persistent opening notice',()=>{
|
||||
const props=input(),html=renderToStaticMarkup(createElement(EmperorPhaseOpeningPriority,props));
|
||||
assert.match(html,/share spice with Ally/);assert.match(html,/Continue to phase/);
|
||||
button(props).props.onClick();assert.deepEqual(props.sent,[{type:'emperorPhaseOpeningContinue',event:'opening'}]);
|
||||
});
|
||||
void test('other viewers see the wait, and stale or busy controls do not submit',()=>{
|
||||
const other=input();other.game.emperorPhaseOpeningPriority!.canContinue=false;
|
||||
assert.match(renderToStaticMarkup(createElement(EmperorPhaseOpeningPriority,other)),/Waiting for the Emperor/);
|
||||
for(const variant of ['busy','event','permission','replace','close'] as const) {
|
||||
const props=input();if(variant==='busy')props.busy=true;const control=button(props);
|
||||
if(variant==='event')props.game.emperorPhaseOpeningPriority!.event='other';
|
||||
if(variant==='permission')props.game.emperorPhaseOpeningPriority!.canContinue=false;
|
||||
if(variant==='replace')props.game.emperorPhaseOpeningPriority={...props.game.emperorPhaseOpeningPriority!};
|
||||
if(variant==='close')props.game.emperorPhaseOpeningPriority=null;
|
||||
control.props.onClick();assert.deepEqual(props.sent,[],variant);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user