diff --git a/tests/e2e/bot/golf-bot.ts b/tests/e2e/bot/golf-bot.ts index 0d7e072..c835364 100644 --- a/tests/e2e/bot/golf-bot.ts +++ b/tests/e2e/bot/golf-bot.ts @@ -72,12 +72,20 @@ export class GolfBot { } /** - * Create a new game room + * Create a new game room. + * + * Works for both guest sessions (fills the name input) and + * authenticated sessions (the name input is hidden; the server + * uses the logged-in username). `playerName` is ignored when the + * session is authenticated. */ async createGame(playerName: string): Promise { - // Enter name + // Guest sessions have a visible player-name input; authenticated + // sessions don't. Only fill it if it's actually there. const nameInput = this.page.locator(SELECTORS.lobby.playerNameInput); - await nameInput.fill(playerName); + if (await nameInput.isVisible().catch(() => false)) { + await nameInput.fill(playerName); + } // Click create room const createBtn = this.page.locator(SELECTORS.lobby.createRoomBtn); @@ -97,12 +105,16 @@ export class GolfBot { } /** - * Join an existing game room + * Join an existing game room. + * + * Same auth handling as `createGame` — `playerName` is ignored for + * authenticated sessions. */ async joinGame(roomCode: string, playerName: string): Promise { - // Enter name const nameInput = this.page.locator(SELECTORS.lobby.playerNameInput); - await nameInput.fill(playerName); + if (await nameInput.isVisible().catch(() => false)) { + await nameInput.fill(playerName); + } // Enter room code const codeInput = this.page.locator(SELECTORS.lobby.roomCodeInput); @@ -172,7 +184,19 @@ export class GolfBot { await this.page.selectOption(SELECTORS.waiting.numRounds, String(options.holes)); } if (options.decks) { - await this.page.selectOption(SELECTORS.waiting.numDecks, String(options.decks)); + // #num-decks is a stepper (hidden input + +/- buttons), not a select. + // Click the stepper until the hidden input matches the requested value. + const target = options.decks; + for (let i = 0; i < 10; i++) { + const current = parseInt( + (await this.page.locator(SELECTORS.waiting.numDecks).inputValue().catch(() => '1')) || '1', + 10, + ); + if (current === target) break; + const btnId = current < target ? '#decks-plus' : '#decks-minus'; + await this.page.locator(btnId).click({ timeout: 1000 }).catch(() => {}); + await this.page.waitForTimeout(50); + } } if (options.initialFlips !== undefined) { await this.page.selectOption(SELECTORS.waiting.initialFlips, String(options.initialFlips));