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; return {game,busy:false,sent,act:(action:Action)=>sent.push(action)}; } function button(props:ReturnType) { 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); } });