Release viewer 2.3.20: consistent action controls and stable resource previews

This commit is contained in:
coyotte508 2026-11-01 21:28:18 +01:00
commit 06bb0aebf6
16 changed files with 417 additions and 66 deletions

View file

@ -0,0 +1,17 @@
{
"game": "powergrid",
"gameVersion": 13,
"publishedAt": "2026-11-01T20:28:11.887Z",
"viewer": {
"version": "2.3.20",
"url": "https://s3.fr-par.scw.cloud/bgs-assets/games/powergrid/13/viewer/split-b941db4298f1f241f1f1/powergrid-viewer.umd.min.js",
"stylesheets": [
"https://s3.fr-par.scw.cloud/bgs-assets/games/powergrid/13/viewer/split-b941db4298f1f241f1f1/powergrid-viewer.css"
],
"scriptBytes": 1222070,
"sha256": "a780e6ed833a202ad26f3697b5e9ca7527d105a1bb439aa20315febc5d5aa7a5",
"bundle": "split-b941db4298f1f241f1f1",
"files": 42
},
"verified": true
}

View file

@ -22,4 +22,16 @@ Remove those two entries from the BGS game-version preferences, preserving all
other entries. Local undo now always removes one unconfirmed action, and board
sizing is always automatic; old saved values for these preferences are ignored.
The phase control pairs a phase pictogram with a skip, finish or edit pictogram.
Only the action inset highlights on hover/focus; the whole control is clickable.
From viewer 2.3.20, the paired pictograms use one shared grey surface with the
same silver/white-border hover as the color-blind and simulation controls. The
separator darkens on hover to preserve contrast. Passing has a normal black
border unless it is the only legal option, when it gets a blue cue. Unaffordable
plants are muted while choosing; the market outline is hidden when there are no
legal plant choices. The resource action shows skip until a purchase is made,
then finish; undoing all purchases restores skip. Phase actions and Undo share
2-unit borders while enabled and 1-unit borders while disabled. Local tentative
previews preserve public deck counters so buying resources does not flash an empty
draw pile. Existing pass-confirmation dialogs are unchanged.
After packaging, run `node viewer/scripts/action-controls-smoke.mjs` to check
normal/only-pass states and hover/focus styling against the board-option buttons.

View file

@ -1,6 +1,6 @@
{
"name": "powergrid-viewer",
"version": "2.3.19",
"version": "2.3.20",
"repository": {
"type": "git",
"url": "git+https://github.com/boardgamers/powergrid.git",

View file

@ -0,0 +1,121 @@
// Run after packaging: node viewer/scripts/action-controls-smoke.mjs
import assert from 'node:assert/strict';
import { chromium } from 'playwright';
import { auctionPreviewServer } from './auction-preview.mjs';
const server = auctionPreviewServer();
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const browser = await chromium.launch({ executablePath: process.env.CHROMIUM_EXECUTABLE });
try {
for (const mode of ['your-turn', 'only-pass']) {
const page = await browser.newPage();
await page.goto(`http://127.0.0.1:${server.address().port}/?mode=${mode}`);
const button = page.locator('[data-board-control="pass"]');
await button.waitFor();
const appearance = () =>
button.evaluate((element) => {
const style = (selector) => {
const css = getComputedStyle(element.querySelector(selector));
return { fill: css.fill, stroke: css.stroke, width: css.strokeWidth };
};
return {
phase: style('.phase-background'),
divider: style('.button-divider'),
phaseIcon: style('[data-phase-icon]'),
actionIcon: style('[data-action-icon]'),
outline: style('.button-outline'),
};
});
const reference = page.locator('[data-board-control="color-blind"]');
const referenceStyle = () =>
reference.locator('.option-background').evaluate((e) => {
const css = getComputedStyle(e);
return { fill: css.fill, stroke: css.stroke, width: css.strokeWidth };
});
const referenceRest = await referenceStyle();
await reference.hover();
const referenceHover = await referenceStyle();
await page.mouse.move(0, 0);
const before = await appearance();
assert.equal(before.phase.fill, referenceRest.fill);
assert.equal(before.outline.stroke, mode === 'only-pass' ? 'rgb(0, 0, 255)' : 'rgb(0, 0, 0)');
assert.equal(await page.locator('[data-market-highlight]').count(), mode === 'only-pass' ? 0 : 1);
const checkHover = async (focused = false) => {
const after = await appearance();
assert.equal(after.outline.stroke, 'rgb(255, 255, 255)');
assert.equal(after.outline.fill, 'none');
assert.equal(after.phase.fill, focused ? referenceRest.fill : referenceHover.fill);
assert.equal(after.outline.width, focused ? '3px' : referenceHover.width);
assert.equal(after.divider.stroke, focused ? before.divider.stroke : 'rgb(89, 102, 108)');
for (const key of ['phaseIcon', 'actionIcon']) {
assert.deepEqual(after[key], before[key], `${key} stays unchanged`);
}
};
for (const side of ['[data-phase-icon]', '[data-action-icon]']) {
await button.locator(side).hover();
await checkHover();
}
await page.mouse.move(0, 0);
assert.deepEqual(await appearance(), before);
await button.focus();
await checkHover(true);
if (mode === 'your-turn') {
const plant = page.locator('[data-market-plant="8"]');
await plant.hover();
assert.equal(
await plant
.locator(':scope > rect')
.first()
.evaluate((e) => getComputedStyle(e).stroke),
'rgb(255, 255, 255)'
);
}
await page.close();
console.log(`${mode}: hover matches board options; focus and market cues passed`);
}
const page = await browser.newPage();
await page.goto(`http://127.0.0.1:${server.address().port}/?mode=resources`);
const phaseButton = page.locator('[data-board-control="pass"]');
await phaseButton.waitFor();
assert(await phaseButton.evaluate((e) => e.classList.contains('skip-action')));
await page.evaluate(() => {
const deck = document.querySelector('[data-board-slot="powerPlantDeck"]');
window.deckSnapshots = [deck.innerHTML];
window.deckObserver = new MutationObserver(() => window.deckSnapshots.push(deck.innerHTML));
window.deckObserver.observe(deck, { childList: true, attributes: true, characterData: true, subtree: true });
});
const echo = page.waitForResponse((response) => response.url().includes('/move?'));
await page.evaluate(() => {
const game = document.querySelector('.game').__vue__;
game.buyResource(game.G.players[0].availableMoves.BuyResource[0]);
});
await echo;
await page.waitForFunction(
() => !document.querySelector('[data-board-control="pass"]').classList.contains('skip-action')
);
const undo = page.locator('[data-board-control="undo"]');
const width = (locator) => locator.evaluate((e) => getComputedStyle(e).strokeWidth);
assert.equal(await width(phaseButton.locator('.button-outline')), '2px');
assert.equal(await width(undo.locator('.undo-background')), '2px');
await undo.click();
await page.waitForFunction(() =>
document.querySelector('[data-board-control="pass"]').classList.contains('skip-action')
);
assert.equal(await width(phaseButton.locator('.button-outline')), '2px');
assert.equal(await width(undo.locator('.undo-background')), '1px', 'disabled undo is thinner');
const snapshots = await page.evaluate(() => {
window.deckObserver.disconnect();
return window.deckSnapshots;
});
assert(
snapshots.every((snapshot) => snapshot === snapshots[0]),
'draw pile stays unchanged during buy/echo/undo'
);
await page.close();
console.log(
'Resources: skip → finish → undo → skip; matching enabled borders, thin disabled border, stable draw pile'
);
} finally {
await browser.close();
await new Promise((resolve) => server.close(resolve));
}

View file

@ -16,15 +16,18 @@ function position(mode) {
'auction-preview'
);
G.round = 2;
G.playerOrder = [2, 0, 1];
G.currentPlayers = [2];
const yourTurn = mode === 'your-turn' || mode === 'only-pass' || mode === 'resources';
if (mode === 'resources') G.phase = engine.Phase.Resources;
G.playerOrder = yourTurn ? [0, 1, 2] : [2, 0, 1];
G.currentPlayers = [yourTurn ? 0 : 2];
const plant = (n) => copy(powerPlants.find((p) => p.number === n));
G.actualMarket = (fastBid ? [17, 19, 20, 21] : [8, 10, 13, 15]).map(plant);
G.futureMarket = [22, 23, 24, 25].map(plant);
G.players.forEach((p, i) => {
p.name = ['You', 'Leo', 'Ada'][i];
p.money = [10, 40, 50][i];
p.money = [mode === 'only-pass' ? 1 : 10, 40, 50][i];
p.powerPlants = [plant([3, 4, 5][i])];
if (mode === 'resources' && i === 0) p.oilCapacity = 4;
p.availableMoves = null;
});
const visible = new Set(
@ -32,16 +35,21 @@ function position(mode) {
);
G.powerPlantsDeck = G.powerPlantsDeck.filter((p) => !visible.has(p.number));
G.cardsLeft = G.powerPlantsDeck.length;
G.players[2].availableMoves = engine.availableMoves(G, G.players[2]);
G.log.push({ type: 'event', event: 'Waiting for Ada to start an auction.' });
const activePlayer = G.players[G.currentPlayers[0]];
activePlayer.availableMoves = engine.availableMoves(G, activePlayer);
G.log.push({
type: 'event',
event: yourTurn ? 'Your turn to start an auction.' : 'Waiting for Ada to start an auction.',
});
G.newTurn = true;
return G;
}
const states = new Map();
const html = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Power Grid · Auction auto-pass preview</title><link rel="stylesheet" href="/bundle.css"><style>body{margin:0;background:#e8ebdf;font-family:system-ui}.preview{display:flex;gap:12px;align-items:center;flex-wrap:wrap;background:#173b32;color:#fff;padding:10px 16px;font-size:13px}.preview button,.preview select{font:inherit;padding:7px}.preview a{color:white}.hint{font-size:13px;padding:8px 16px;margin:0;background:#edf1e8;color:#253b2c}#error{color:#9e1515}#error:empty{display:none}</style></head><body><header class="preview"><strong>Local preview</strong><select id="mode" aria-label="Auction scenario"><option value="public">Public money · open auction</option><option value="hidden">Hidden money · open auction</option><option value="public-sealed">Public money · sealed auction</option><option value="hidden-sealed">Hidden money · sealed auction</option></select><button id="opponent">Ada bids 10</button><button id="reset">Reset</button><a href="/mobile">Mobile preview</a></header><p class="hint">You have 10. With hidden money, try the auto-pass checkbox in your player card before Ada bids.</p><p id="error" role="alert"></p><div id="app"></div><script src="/vue.js"></script><script src="/bundle.js"></script><script>
const html = `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Power Grid · Auction auto-pass preview</title><link rel="stylesheet" href="/bundle.css"><style>body{margin:0;background:#e8ebdf;font-family:system-ui}.preview{display:flex;gap:12px;align-items:center;flex-wrap:wrap;background:#173b32;color:#fff;padding:10px 16px;font-size:13px}.preview button,.preview select{font:inherit;padding:7px}.preview a{color:white}.hint{font-size:13px;padding:8px 16px;margin:0;background:#edf1e8;color:#253b2c}#error{color:#9e1515}#error:empty{display:none}</style></head><body><header class="preview"><strong>Local preview</strong><select id="mode" aria-label="Auction scenario"><option value="your-turn">Your turn · start an auction</option><option value="only-pass">Your turn · only passing is possible</option><option value="resources">Your turn · buy resources</option><option value="public">Public money · open auction</option><option value="hidden">Hidden money · open auction</option><option value="public-sealed">Public money · sealed auction</option><option value="hidden-sealed">Hidden money · sealed auction</option></select><button id="opponent">Ada bids 10</button><button id="reset">Reset</button><a href="/mobile">Mobile preview</a></header><p class="hint">You have 10. With hidden money, try the auto-pass checkbox in your player card before Ada bids.</p><p id="error" role="alert"></p><div id="app"></div><script src="/vue.js"></script><script src="/bundle.js"></script><script>
const query=new URLSearchParams(location.search),mode=query.get('mode')||'public';
const host=window.host=powergrid.launch('#app');
document.querySelector('#mode').value=mode;
if(mode==='only-pass')document.querySelector('.hint').textContent='You have 1. No plant is affordable, so passing is the only legal action.';
document.querySelector('#mode').onchange=e=>location.search='?mode='+e.target.value;
async function send(path,body){const response=await fetch(path+'?mode='+mode,{method:body?'POST':'GET',headers:{'Content-Type':'application/json'},body:body?JSON.stringify(body):undefined});const data=await response.json();document.querySelector('#error').textContent=data.error||'';if(data.error)return;host.emit('settings',data.settings);host.emit('state',data.state);const button=document.querySelector('#opponent');button.textContent=data.next;button.disabled=!data.opponent;}
host.on('fetchState',()=>send('/state'));host.on('move',move=>send('/move',{move}));host.on('update:setting',setting=>send('/setting',setting));

View file

@ -470,7 +470,7 @@
<PassButton
transform="translate(15, 15)"
:enabled="canUsePhaseButton"
:highlightButton="canUsePhaseButton"
:highlightButton="highlightPhaseButton"
:text="phaseButtonText"
:icon="phaseButtonIcon"
:action="phaseButtonAction"
@ -902,6 +902,7 @@
</template>
<script lang="ts">
import { isEqual } from 'lodash';
import './buttons/board-control.css';
import { resolvePlayerColors, colorText } from '../player-colors';
import InlineLog from './InlineLog.vue';
import { Vue, Component, Prop, Watch, Provide, ProvideReactive, Ref } from 'vue-property-decorator';
@ -1350,6 +1351,14 @@ export default class Game extends Vue {
if (this.changingBid) return this.player !== this.G!.auctioningPlayer;
return !!this.revisableBid || this.canChangePowering || this.canPass();
}
get highlightPhaseButton(): boolean {
if (!this.canUsePhaseButton) return false;
if (this.phaseButtonAction !== 'skip') return true;
if (this.changingBid) return this.revisionBids.length === 0;
const moves = this.G?.players[this.player!]?.availableMoves;
if (this.G?.phase === Phase.Resources) return !moves?.[MoveName.BuyResource]?.length;
return !moves?.[MoveName.Bid]?.length && !moves?.[MoveName.ChoosePowerPlant]?.length;
}
get phaseButtonText(): string {
if (this.changingBid) return 'Pass bid';
if (this.revisableBid) return 'Edit bid';
@ -1371,6 +1380,7 @@ export default class Game extends Vue {
get phaseButtonAction(): string {
if ((this.revisableBid && !this.changingBid) || this.canChangePowering) return 'edit';
if (this.changingBid) return 'skip';
if (this.G?.phase === Phase.Resources) return this.playerBoughtResourceThisTurn() ? 'finish' : 'skip';
if (this.tutorialMove || this.roundPlan) return 'finish';
return this.G?.phase === Phase.Auction ? 'skip' : 'finish';
}

View file

@ -16,7 +16,12 @@
:key="card.id"
:targetState="{ x: card.x, y: card.y }"
:powerPlant="card.powerPlant"
:canClick="chooseablePowerPlants && chooseablePowerPlants.includes(card.powerPlant.number)"
:class="{
'unavailable-plant':
canChoose && !(chooseablePowerPlants && chooseablePowerPlants.includes(card.powerPlant.number)),
}"
:data-market-plant="card.powerPlant.number"
:canClick="canChoose && chooseablePowerPlants && chooseablePowerPlants.includes(card.powerPlant.number)"
:hasDiscount="plantDiscountActive && i == 0"
@click="choosePowerPlant(card.powerPlant)"
/>
@ -50,33 +55,21 @@
/>
</template>
<template>
<g v-if="canChoose">
<rect
v-if="futureMarketCards.length > 0"
x="160"
y="5"
:width="65 * actualMarketCards.length + 5"
height="65"
fill="none"
stroke="blue"
stroke-width="2px"
rx="2px"
/>
<rect
v-else
x="160"
y="5"
:width="actualMarketHighlightWidth"
height="120"
fill="none"
stroke="blue"
stroke-width="2px"
rx="2px"
/>
</g>
</template>
<!-- Keep the active market grouped; unavailable choices are muted individually. -->
<rect
v-if="canChoose && hasAvailablePlant"
data-market-highlight
x="160"
y="5"
:width="marketHighlightWidth"
:height="marketHighlightHeight"
fill="none"
stroke="blue"
stroke-width="2"
rx="2"
pointer-events="none"
aria-hidden="true"
/>
</g>
</template>
@ -115,7 +108,17 @@ export default class PowerPlantMarket extends Vue {
futureMarketCards: Piece[] = [];
chosenPowerPlant: Piece | null = null;
actualMarketWidth: number = 430;
actualMarketHighlightWidth: number = 200;
get hasAvailablePlant(): boolean {
return this.actualMarketCards.some((card) => this.chooseablePowerPlants?.includes(card.powerPlant!.number));
}
get marketHighlightWidth(): number {
return Math.max(...this.actualMarketCards.map((card) => card.x + 65)) - 160;
}
get marketHighlightHeight(): number {
return Math.max(...this.actualMarketCards.map((card) => card.y + 46)) - 5;
}
createPieces(gameState: GameState) {
this.actualMarketWidth = gameState.map.actualMarketWidth ?? 430;
@ -124,7 +127,7 @@ export default class PowerPlantMarket extends Vue {
// "whole market buyable" state keeps up to 8 in the actual market — wrap
// at 4 per row there so cards 7 and 8 don't paint on top of the second row.
const actualPerRow = gameState.actualMarket.length > 6 ? 4 : 3;
this.actualMarketHighlightWidth = 65 * Math.min(gameState.actualMarket.length, actualPerRow) + 5;
gameState.actualMarket.forEach((card, i) => {
if (gameState.futureMarket.length > 0) {
if (card.number != gameState.chosenPowerPlant?.number) {
@ -183,3 +186,10 @@ export default class PowerPlantMarket extends Vue {
}
}
</script>
<style scoped>
.unavailable-plant {
filter: grayscale(0.85);
opacity: 0.45;
}
</style>

View file

@ -11,7 +11,7 @@
@keydown.enter.prevent="$emit('click')"
@keydown.space.prevent="$emit('click')"
>
<rect class="option-background" width="36" height="26" rx="4" stroke="black" />
<rect class="option-background board-control-border" width="36" height="26" rx="4" stroke="black" />
<g transform="translate(7, 2)" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true">
<template v-if="icon === 'shapes'">
<path d="M6 1L11 9H1Z" />
@ -64,14 +64,8 @@ export default class BoardOption extends Vue {
.active {
color: white;
}
.board-option:hover .option-background {
stroke-width: 2;
}
.board-option:focus {
outline: none;
}
.board-option:focus-visible .option-background {
stroke: #fff;
stroke-width: 3;
}
</style>

View file

@ -1,6 +1,6 @@
<template>
<g
:class="['button', { enabled, highlightButton }]"
:class="['button', { enabled, highlightButton, 'skip-action': action === 'skip' }]"
data-board-control="pass"
role="button"
:aria-label="text"
@ -10,13 +10,12 @@
@keydown.enter.prevent="enabled && $emit('click')"
@keydown.space.prevent="enabled && $emit('click')"
>
<rect class="phase-background" width="80" height="26" fill="#e9edef" stroke="black" rx="3" />
<path class="action-background" d="M49 1H77Q79 1 79 3V23Q79 25 77 25H49Z" fill="#d1dce0" />
<path d="M49 3V23" stroke="#adbdc4" aria-hidden="true" />
<path class="phase-background" d="M4 0H76Q80 0 80 4V22Q80 26 76 26H4Q0 26 0 22V4Q0 0 4 0Z" fill="gainsboro" />
<path class="button-divider" d="M40 0V26" stroke="#88949a" aria-hidden="true" />
<path
:d="iconPath"
data-phase-icon
transform="translate(17, 4.5)"
transform="translate(12, 5)"
fill="none"
stroke="black"
stroke-width="1.5"
@ -27,14 +26,24 @@
<path
:d="actionPath"
data-action-icon
transform="translate(56, 5.5) scale(0.9)"
transform="translate(52, 5)"
fill="none"
stroke="black"
stroke-width="1.6"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
/>
<!-- Paint the shared outline last so neither half can cover the highlight. -->
<rect
class="button-outline board-control-border turn-action-border"
width="80"
height="26"
fill="none"
stroke="black"
rx="4"
pointer-events="none"
/>
<title>{{ text }}</title>
</g>
</template>
@ -51,7 +60,7 @@ export default class PassButton extends Vue {
get actionPath(): string {
const paths: Record<string, string> = {
skip: 'M16 8A7 7 0 1 1 2 8A7 7 0 1 1 16 8Z M4 3L14 13',
skip: 'M16 8A8 8 0 1 1 0 8A8 8 0 1 1 16 8Z M2.34 2.34L13.66 13.66',
finish: 'M1 9L6 14L16 2',
edit: 'M2 11L12 1L16 5L6 15L1 16Z M10 3L14 7',
};
@ -73,17 +82,19 @@ export default class PassButton extends Vue {
</script>
<style scoped>
/* The whole control is clickable, but only the action inset reacts. Keep the
phase context unchanged instead of inheriting the board's generic hover. */
/* Match the color-blind/simulation controls: one grey surface, black border,
then silver with a white border on hover. Keep the icons unchanged. */
.button .button-outline {
fill: none;
}
.button.enabled:hover .phase-background {
fill: #e9edef;
stroke: black;
fill: silver;
}
.button.enabled.highlightButton:hover .phase-background {
stroke: blue;
.button.enabled:hover .button-divider {
stroke: #59666c;
}
.button.enabled:hover .action-background,
.button.enabled:focus-visible .action-background {
fill: white;
.button.enabled:hover .button-outline,
.button.enabled:focus-visible .button-outline {
fill: none;
}
</style>

View file

@ -10,7 +10,14 @@
@keydown.enter.prevent="enabled && $emit('click')"
@keydown.space.prevent="enabled && $emit('click')"
>
<rect width="80" height="26" fill="gainsboro" stroke="black" rx="2" />
<rect
class="undo-background board-control-border turn-action-border"
width="80"
height="26"
fill="gainsboro"
stroke="black"
rx="4"
/>
<image
v-if="icon === 'undo'"
x="30"

View file

@ -0,0 +1,20 @@
/* Shared border treatment for phase actions, Undo and board-option controls.
Backgrounds/icons remain owned by their components. */
.button .board-control-border {
stroke-width: 1px;
}
.button.enabled .turn-action-border {
stroke-width: 2px;
}
.button.enabled.highlightButton .board-control-border {
stroke: blue;
stroke-width: 2px;
}
.button.enabled:hover .board-control-border {
stroke: white;
stroke-width: 2px;
}
.button.enabled:focus-visible .board-control-border {
stroke: white;
stroke-width: 3px;
}

View file

@ -160,4 +160,7 @@ export default class Card extends Mixins(Piece) {
.canClick {
cursor: pointer;
}
[data-market-plant].canClick:hover > rect:first-of-type {
stroke: white;
}
</style>

View file

@ -182,6 +182,13 @@ export function replayTurnBuffer(
for (const move of turnMoves) {
try {
state = engineMove(state, move, player);
// The viewer receives an empty secret deck, not an exhausted deck.
// Tentative moves cannot draw cards; retain the public counters rather
// than flashing an empty pile until the server's echo restores them.
if (committedState.seed === 'secret' && state.newTurn === false) {
state.cardsLeft = committedState.cardsLeft;
state.nextCardWeak = committedState.nextCardWeak;
}
} catch (err) {
console.error('dropping turn-buffer tail no longer legal on the committed state', move, err);
failure = err;

View file

@ -66,7 +66,7 @@ describe('phase button', () => {
it('pairs distinct phase icons with skip or finish and complete accessible labels', () => {
const paths: string[] = [];
for (const phase of [Phase.Auction, Phase.Resources, Phase.Building, Phase.Bureaucracy]) {
const context = { G: { phase } };
const context = { G: { phase }, playerBoughtResourceThisTurn: () => true };
const text = computed('phaseButtonText', context);
const icon = computed('phaseButtonIcon', context);
const action = computed('phaseButtonAction', context);
@ -82,6 +82,77 @@ describe('phase button', () => {
expect(new Set(paths).size).to.equal(4);
});
it('highlights skip only when neither bidding nor choosing a plant is legal', () => {
const context = (availableMoves: any) => ({
canUsePhaseButton: true,
phaseButtonAction: 'skip',
player: 0,
G: { players: [{ availableMoves }] },
});
expect(computed('highlightPhaseButton', context({ Pass: true }))).to.equal(true);
expect(computed('highlightPhaseButton', context({ Pass: true, Bid: [11] }))).to.equal(false);
expect(computed('highlightPhaseButton', context({ Pass: true, ChoosePowerPlant: [8] }))).to.equal(false);
expect(computed('highlightPhaseButton', { ...context({}), canUsePhaseButton: false })).to.equal(false);
expect(computed('highlightPhaseButton', { ...context({}), changingBid: true, revisionBids: [8] })).to.equal(
false
);
expect(computed('highlightPhaseButton', { ...context({}), changingBid: true, revisionBids: [] })).to.equal(
true
);
});
it('shows skip until a resource is bought and restores skip after all buys are undone', () => {
const context: any = { player: 0, G: { phase: Phase.Resources, log: [] } };
context.playerBoughtResourceThisTurn = () => options.methods.playerBoughtResourceThisTurn.call(context);
expect(computed('phaseButtonAction', context)).to.equal('skip');
context.G.log.push({ type: 'move', player: 0, move: { name: 'BuyResource' } });
expect(computed('phaseButtonAction', context)).to.equal('finish');
context.G.log.pop();
expect(computed('phaseButtonAction', context)).to.equal('skip');
context.G.log.push({ type: 'move', player: 1, move: { name: 'BuyResource' } });
expect(computed('phaseButtonAction', context)).to.equal('skip');
});
it('highlights resource skip only when buying is unavailable', () => {
const context: any = {
canUsePhaseButton: true,
phaseButtonAction: 'skip',
player: 0,
G: {
phase: Phase.Resources,
players: [{ availableMoves: { Pass: true, BuyResource: [{ resource: 'coal' }] } }],
},
};
expect(computed('highlightPhaseButton', context)).to.equal(false);
context.G.players[0].availableMoves.BuyResource = [];
expect(computed('highlightPhaseButton', context)).to.equal(true);
});
it('keeps skip styling while accepting the only-option highlight', async () => {
const wrapper = mount(PassButton, {
propsData: { text: 'Pass bid', action: 'skip', enabled: true, highlightButton: false },
});
expect(wrapper.classes()).to.include('skip-action');
expect(wrapper.classes()).not.to.include('highlightButton');
await wrapper.setProps({ highlightButton: true });
expect(wrapper.classes()).to.include('highlightButton');
wrapper.destroy();
});
it('uses equal-scale icons and paints one shared outline above both backgrounds', () => {
const wrapper = mount(PassButton, { propsData: { text: 'Pass bid', icon: 'auction', action: 'skip' } });
expect(wrapper.find('[data-phase-icon]').attributes('transform')).to.equal('translate(12, 5)');
expect(wrapper.find('[data-action-icon]').attributes('transform')).to.equal('translate(52, 5)');
const children = Array.from(wrapper.element.children);
const outline = wrapper.find('.button-outline');
expect(children.indexOf(outline.element)).to.be.greaterThan(
children.indexOf(wrapper.find('[data-action-icon]').element)
);
expect(outline.attributes('fill')).to.equal('none');
expect(outline.attributes('pointer-events')).to.equal('none');
wrapper.destroy();
});
it('keeps the phase visible when editing and uses skip when passing a revised bid', () => {
for (const context of [
{ G: { phase: Phase.Auction }, revisableBid: 'bid' },

View file

@ -0,0 +1,33 @@
import PowerPlantMarket from '@/components/boards/PowerPlantMarket.vue';
import { shallowMount } from '@vue/test-utils';
import { expect } from 'chai';
describe('market choice highlights', () => {
it('groups the market while muting unavailable choices and follows eligibility changes', async () => {
const wrapper = shallowMount(PowerPlantMarket, {
propsData: { canChoose: true, chooseablePowerPlants: [8, 10] },
provide: { preferences: {} },
});
await wrapper.setData({
actualMarketCards: [
{ id: 'a', x: 165, y: 24, powerPlant: { number: 8 } },
{ id: 'b', x: 230, y: 24, powerPlant: { number: 13 } },
{ id: 'c', x: 165, y: 80, powerPlant: { number: 10 } },
],
});
const unavailable = () =>
wrapper.findAll('.unavailable-plant').wrappers.map((w) => w.attributes('data-market-plant'));
expect(unavailable()).to.deep.equal(['13']);
expect(wrapper.find('[data-market-highlight]').attributes('height')).to.equal('121');
expect(wrapper.find('[data-market-highlight]').attributes('pointer-events')).to.equal('none');
await wrapper.setProps({ chooseablePowerPlants: [13] });
expect(unavailable()).to.deep.equal(['8', '10']);
await wrapper.setProps({ canChoose: false });
expect(unavailable()).to.deep.equal([]);
expect(wrapper.find('[data-market-highlight]').exists()).to.equal(false);
await wrapper.setProps({ canChoose: true, chooseablePowerPlants: [] });
expect(unavailable()).to.deep.equal(['8', '13', '10']);
expect(wrapper.find('[data-market-highlight]').exists()).to.equal(false);
wrapper.destroy();
});
});

View file

@ -245,6 +245,33 @@ describe('turn-buffer', () => {
expect(state.players[player].availableMoves![MoveName.ChoosePowerPlant]).to.be.undefined;
});
it('preserves public deck counters while previewing purchases on a secret deck', () => {
let G: GameState = setup(4, { variant: 'recharged' }, 'turn-buffer-resources');
for (let i = 0; i < 4000; i++) {
const seat = G.players.findIndex((p) => p.availableMoves);
if (seat < 0) break;
const buys = G.players[seat].availableMoves![MoveName.BuyResource];
if (G.phase === Phase.Resources && buys && buys.length) {
const stripped = stripSecret(clone(G), seat);
expect(stripped.powerPlantsDeck).to.deep.equal([]);
expect(stripped.cardsLeft).to.be.greaterThan(0);
const buy: Move = { name: MoveName.BuyResource, data: buys[0], time: 1000 };
const preview = replayTurnBuffer(stripped, [buy], seat);
expect(preview.failure).to.equal(undefined);
expect(preview.state.newTurn).to.equal(false);
expect(preview.state.cardsLeft).to.equal(stripped.cardsLeft);
expect(preview.state.nextCardWeak).to.equal(stripped.nextCardWeak);
const server = stripSecret(engineMove(clone(G), buy, seat), seat);
expect(preview.state.cardsLeft).to.equal(server.cardsLeft);
expect(preview.state.nextCardWeak).to.equal(server.nextCardWeak);
expect(replayTurnBuffer(stripped, [], seat).state.cardsLeft).to.equal(stripped.cardsLeft);
return;
}
G = moveAI(G, seat);
}
expect.fail('never reached a resource purchase');
});
it('a preview after every buy stops a resource click going past storage capacity', () => {
// Drive a real game to a seat that can buy resources.
let G: GameState = setup(4, {}, 'turn-buffer-resources');