|
| 1 | +import { Locator, type Page, expect } from "@playwright/test"; |
| 2 | + |
| 3 | +export class ImportPage { |
| 4 | + private readonly url: string; |
| 5 | + private nameInputField: Locator; |
| 6 | + private startSessionBtn: Locator; |
| 7 | + |
| 8 | + constructor(public readonly page: Page) { |
| 9 | + this.url = `http://localhost:5173${ |
| 10 | + process.env.CI ? process.env.BASE_URL : "/" |
| 11 | + }`; |
| 12 | + |
| 13 | + this.startSessionBtn = page.getByRole("button", { name: "Start session" }); |
| 14 | + this.nameInputField = page.getByRole("textbox", { name: "Name" }); |
| 15 | + } |
| 16 | + |
| 17 | + async gotoSimpleAIExerciseTimer() { |
| 18 | + // The import process relies on the e2e flag in this query string |
| 19 | + // for the proxy to be used. |
| 20 | + const query = |
| 21 | + "flag=e2e&id=simple-ai-exercise-timer&project=Project%3A%20Simple%20AI%20exercise%20timer&name=Simple%20AI%20exercise%20timer&editors=makecode"; |
| 22 | + return this.page.goto(`${this.url}import?${query}`); |
| 23 | + } |
| 24 | + |
| 25 | + expectName(expected: string) { |
| 26 | + return expect(this.nameInputField).toHaveValue(expected); |
| 27 | + } |
| 28 | + |
| 29 | + async startSession() { |
| 30 | + // Might still be loading. |
| 31 | + await expect(this.startSessionBtn).toBeEnabled({ |
| 32 | + timeout: 5_000, |
| 33 | + }); |
| 34 | + await this.startSessionBtn.click(); |
| 35 | + } |
| 36 | + |
| 37 | + async expectOnPage() { |
| 38 | + await expect(this.page.getByText("New session setup")).toBeVisible(); |
| 39 | + await expect(this.nameInputField).toBeVisible(); |
| 40 | + await expect(this.startSessionBtn).toBeVisible(); |
| 41 | + } |
| 42 | +} |
0 commit comments