import assert from 'node:assert/strict'; import test from 'node:test'; import {Children, createElement, isValidElement} from 'react'; import {renderToStaticMarkup} from 'react-dom/server'; import {EmperorTimingGift} from '../components/emperor-timing-gift'; import {EmperorGuildRatePriority} from '../components/emperor-guild-rate-priority'; import type {Action, GameView} from '../game/engine'; function priorityProps() { const sent:Action[] = []; const game = {emperorGuildRatePriority:{event:'rate-event',recipient:'guild',canContinue:true}, players:[{id:'guild',name:'Guild'}]} as unknown as Pick; return {game, busy:false, sent, act:(action:Action) => sent.push(action)}; } function button(props:ReturnType) { const panel = EmperorGuildRatePriority(props); assert.ok(panel); const row = Children.toArray(panel.props.children).find(child => isValidElement(child) && child.type === 'button'); assert.ok(isValidElement<{onClick:()=>void;disabled:boolean}>(row)); return row; } void test('Guild rate opportunity offers a persistent Continue to the Emperor', () => { const props=priorityProps(); const html=renderToStaticMarkup(createElement(EmperorGuildRatePriority,props)); assert.match(html,/Emperor may share spice with Guild/); assert.match(html,/Continue to Guild rate/); button(props).props.onClick(); assert.deepEqual(props.sent,[{type:'emperorGuildRateContinue',event:'rate-event'}]); }); void test('other seats see a neutral wait and stale or busy Continue controls do not submit', () => { const other=priorityProps();other.game.emperorGuildRatePriority!.canContinue=false; assert.match(renderToStaticMarkup(createElement(EmperorGuildRatePriority,other)),/Waiting for the Emperor/); for(const variant of ['busy','event','permission','replace','close'] as const) { const props=priorityProps();if(variant==='busy')props.busy=true;const control=button(props); if(variant==='event')props.game.emperorGuildRatePriority!.event='another-event'; if(variant==='permission')props.game.emperorGuildRatePriority!.canContinue=false; if(variant==='replace')props.game.emperorGuildRatePriority={...props.game.emperorGuildRatePriority!}; if(variant==='close')props.game.emperorGuildRatePriority=null; control.props.onClick();assert.deepEqual(props.sent,[],variant); } }); void test('the private Guild rate quote shows the existing gift form and amount limits', () => { const game={emperorPhaseOpeningGift:null,emperorExtortionGift:null,emperorGuildTimingGift:null, emperorGuildRateGift:{recipient:'guild',maximum:4},players:[{id:'guild',name:'Guild'}]} as unknown as GameView; const render=(view:GameView,busy=false)=>renderToStaticMarkup(createElement(EmperorTimingGift,{game:view,busy,act(){}})); const html=render(game); assert.match(html,/Share spice with Guild/); assert.match(html,/original Guild rate response resumes/); assert.match(html,/type="number"[^>]*min="1"[^>]*max="4"/); assert.match(html,/]*disabled)[^>]*>Share spice<\/button>/); assert.match(render(game,true),/]*disabled=""[^>]*>Share spice<\/button>/); assert.equal(render({...game,emperorGuildRateGift:null}),''); });