import { expect, type Page } from "@playwright/test"; /** Play a new game's introduction through the real controls: the gender * menu, the clock (kept at the device time) and a name. An empty name * picks the gender's first preset (CHRIS or KRIS). */ export async function completeIntro( page: Page, { girl = false, name = "" } = {}, ) { const screen = page.locator("#game-screen"), choice = page.locator("#dialogue-choice"); await expect(screen).toHaveAttribute("data-intro", "true"); await choice.getByRole("option", { name: girl ? "Girl" : "Boy" }).click(); for ( let guard = 0; guard < 80 && (await screen.getAttribute("data-intro")) === "true"; guard++ ) { if (!(await choice.isVisible())) { await page.locator("#dialogue-next").click(); continue; } const menu = choice.getByRole("option"); if (await choice.locator("input").count()) { await choice.locator("input").fill(name); await choice.getByRole("button", { name: "OK" }).click(); } else if (await menu.count()) await menu.nth(name ? 0 : 1).click(); else if (await choice.getByRole("button", { name: "YES" }).count()) await choice.getByRole("button", { name: "YES" }).click(); else await choice.getByRole("button", { name: "OK" }).click(); } await expect(screen).toHaveAttribute("data-intro", "false"); }