|
1 | 1 | import { base64Encode } from "@opencode/util/encode" |
2 | | -import { expect, test } from "@playwright/test" |
| 2 | +import { expect, test, type Locator } from "@playwright/test" |
3 | 3 | import { NO_PROVIDER, REMOTE_SERVER, SERVER, holdRoute, project, provider, session } from "../utils/app" |
4 | 4 | import { mockOpenCodeServer, mockServers } from "../utils/mock-server" |
5 | 5 | import { expectSessionTitle } from "../utils/waits" |
6 | 6 |
|
7 | 7 | test.use({ viewport: { width: 1280, height: 900 } }) |
8 | 8 |
|
| 9 | +test("WSL distribution radios stay inset and aligned in both add-server lists", async ({ page }) => { |
| 10 | + await mockOpenCodeServer(page, { |
| 11 | + directory: "/repo", |
| 12 | + project: project({ id: "proj_wsl_alignment", directory: "/repo", name: "WSL project" }), |
| 13 | + provider: NO_PROVIDER, |
| 14 | + sessions: [], |
| 15 | + pageMessages: () => ({ items: [] }), |
| 16 | + }) |
| 17 | + await page.goto( |
| 18 | + `/e2e/utils/settings-wsl.html?${new URLSearchParams({ |
| 19 | + server: SERVER, |
| 20 | + mode: "ready", |
| 21 | + distros: "Ubuntu-24.04,AlmaLinux-9,Debian-WSL1", |
| 22 | + })}`, |
| 23 | + ) |
| 24 | + const settings = page.getByTestId("settings-screen") |
| 25 | + await settings.getByRole("tab", { name: "Servers", exact: true }).click() |
| 26 | + await expect(settings.getByRole("region", { name: "Ubuntu", exact: true })).toHaveCount(1) |
| 27 | + await settings.getByRole("button", { name: "Add server", exact: true }).press("Enter") |
| 28 | + await page.getByRole("menuitem", { name: "Add WSL server", exact: true }).click() |
| 29 | + const dialog = page.getByRole("dialog") |
| 30 | + const ubuntu = dialog.getByRole("radio", { name: "Ubuntu-24.04 OpenCode not installed", exact: true }) |
| 31 | + const alma = dialog.getByRole("radio", { name: "AlmaLinux-9 OpenCode not installed", exact: true }) |
| 32 | + await expect(ubuntu).toBeEnabled() |
| 33 | + await expect(dialog.getByText("OpenCode not installed", { exact: true })).toHaveCount(2) |
| 34 | + await expect(dialog.getByRole("radio", { name: "Debian-WSL1 Unsupported · Use WSL 2", exact: true })).toBeDisabled() |
| 35 | + await expectDistroLayout(dialog) |
| 36 | + await dialog |
| 37 | + .locator('[data-slot="radio-v2-item-label"]') |
| 38 | + .filter({ has: page.getByText("AlmaLinux-9", { exact: true }) }) |
| 39 | + .click() |
| 40 | + await expect(alma).toBeChecked() |
| 41 | + await alma.press("ArrowUp") |
| 42 | + await expect(ubuntu).toBeChecked() |
| 43 | + await expect(ubuntu).toBeFocused() |
| 44 | + await expectDistroLayout(dialog) |
| 45 | + |
| 46 | + await dialog.getByRole("button", { name: /Need another distro/ }).click() |
| 47 | + await expect(dialog.getByRole("heading", { name: "Install distro", exact: true })).toBeVisible() |
| 48 | + await expect(dialog.getByRole("radio", { name: "Debian", exact: true })).toBeChecked() |
| 49 | + await expectDistroLayout(dialog) |
| 50 | + await dialog |
| 51 | + .locator('[data-slot="radio-v2-item-label"]') |
| 52 | + .filter({ has: page.getByText("FedoraLinux-43", { exact: true }) }) |
| 53 | + .click() |
| 54 | + await expect(dialog.getByRole("radio", { name: "FedoraLinux-43", exact: true })).toBeChecked() |
| 55 | + await expectDistroLayout(dialog) |
| 56 | +}) |
| 57 | + |
| 58 | +async function expectDistroLayout(dialog: Locator) { |
| 59 | + // Keep the visible control inside its row and aligned with its label, including disabled rows, |
| 60 | + // and keep rows flush so every divider sits the same distance from the content below it. |
| 61 | + await expect |
| 62 | + .poll(() => |
| 63 | + dialog.locator(".settings-wsl-distro-row").evaluateAll((rows) => |
| 64 | + rows.every((row, index) => { |
| 65 | + const previous = rows[index - 1]?.getBoundingClientRect() |
| 66 | + |
| 67 | + if (previous && Math.abs(row.getBoundingClientRect().top - previous.bottom) > 1) return false |
| 68 | + const control = row.querySelector('[data-slot="radio-v2-item-control"]') |
| 69 | + const label = row.querySelector('[data-slot="radio-v2-item-label-text"]') |
| 70 | + |
| 71 | + if (!control || !label) return false |
| 72 | + const bounds = row.getBoundingClientRect() |
| 73 | + const circle = control.getBoundingClientRect() |
| 74 | + const text = label.getBoundingClientRect() |
| 75 | + |
| 76 | + return ( |
| 77 | + circle.left - bounds.left >= 8 && |
| 78 | + circle.top - bounds.top >= 8 && |
| 79 | + circle.bottom < bounds.bottom && |
| 80 | + circle.right < text.left && |
| 81 | + Math.abs(circle.top + circle.height / 2 - (text.top + text.height / 2)) <= 4 |
| 82 | + ) |
| 83 | + }), |
| 84 | + ), |
| 85 | + ) |
| 86 | + .toBe(true) |
| 87 | +} |
| 88 | + |
9 | 89 | for (const mode of ["failed", "stopped", "ready"] as const) { |
10 | 90 | test(`manages a ${mode} configured WSL server from the Servers page`, async ({ page }) => { |
11 | 91 | await mockOpenCodeServer(page, { |
|
0 commit comments