import assert from 'node:assert/strict'; import test from 'node:test'; import { createElement } from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { PhaseAnyBidGuideButton, PhaseAnyBidPromises } from '../components/phase-any-bid-promises'; import { createGame, joinGame, newPlayer, viewGame, type Action, type GameView } from '../game/engine'; import { createRicheseAuction, projectRicheseAuction } from '../game/richese-auction'; /** Controlled view tests verify only display and exact callback guards; native * public-start question, auction and payment evidence belongs to runtime tests. */ function projected(): GameView { const source = createGame('PHASEANYBIDCONTROLS',newPlayer('p','Respondent','emperor'),false); joinGame(source,newPlayer('a','Asker','atreides')); const game = viewGame(source,'p'); game.status = 'playing'; game.phase = 3; game.turn = 2; game.auction = {bid:1,bidder:'a',active:'p',remaining:2,inspectionBlocked:null,card:null}; game.bidPromiseLot = {turn:2,lot:1}; game.phaseAnyBidPromises = [{turn:2,minimum:4,event:'promise',player:'p',asker:'a',answer:true}]; game.phaseAnyBidGuide = {action:{type:'bid',amount:4,allyPayment:0, phaseAnyBidPromiseEvent:'promise',phaseAnyBidLot:1}}; return game; } void test('any-auction promise describes all auction sources and exact owned ordinary guide', () => { const game = projected(), sent: Action[] = []; const markup = renderToStaticMarkup(createElement(PhaseAnyBidPromises,{game,busy:false,send() {}})); assert.match(markup,/ordinary, Richese cache, or Black Market auction/); assert.match(markup,/Some combinations with other bidding commitments remain unavailable/); const button = PhaseAnyBidGuideButton({game,busy:false,send:action => sent.push(action)}); assert.ok(button); button.props.onClick(); assert.deepEqual(sent,[game.phaseAnyBidGuide!.action]); game.auction!.bid = 2; button.props.onClick(); assert.equal(sent.length,1); }); void test('busy, completed, wrong owner and stale ordinary guide callbacks do not send', () => { const game = projected(), sent: Action[] = []; const busy = PhaseAnyBidGuideButton({game,busy:true,send:action => sent.push(action)}); assert.ok(busy); assert.equal(busy.props.disabled,true); busy.props.onClick(); const button = PhaseAnyBidGuideButton({game,busy:false,send:action => sent.push(action)}); assert.ok(button); game.phaseAnyBidPromises[0].fulfilled = true; button.props.onClick(); game.phaseAnyBidPromises[0].fulfilled = false; game.auction!.active = 'a'; button.props.onClick(); game.auction!.active = 'p'; game.bidPromiseLot!.lot = 2; button.props.onClick(); assert.deepEqual(sent,[]); }); for (const method of ['onceAround','silent'] as const) void test(`the ${method} guide checks its exact Richese lot and submission state`, () => { const game = projected(), sent: Action[] = []; game.auction = null; const native = createRicheseAuction({event:'lot',cardId:'card',source:'cache',owner:'a',method, eligible:['p','a'],order:['p','a'],tieOrder:['p','a']}); game.richeseAuction = {...projectRicheseAuction(native,'p'),card:null,claim:null, ownAllyPayment:0,ownAvailable:5,allyAvailable:0,peekKnown:false,inspectionBlocked:null}; game.phaseAnyBidGuide = {action:{type:'richeseBid',event:'lot',amount:4,allyPayment:0, phaseAnyBidPromiseEvent:'promise',phaseAnyBidLotEvent:'lot'}}; const button = PhaseAnyBidGuideButton({game,busy:false,send:action => sent.push(action)}); assert.ok(button); button.props.onClick(); assert.equal(sent.length,1); if (method === 'silent') game.richeseAuction.submitted.push('p'); else game.richeseAuction.active = 'a'; button.props.onClick(); assert.equal(sent.length,1); });