Skip to content

Commit 4873a93

Browse files
inuyumeHona
andauthored
fix(gui-plugins): correct WSL radio alignment (#53676)
Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com>
1 parent fe659c2 commit 4873a93

4 files changed

Lines changed: 115 additions & 8 deletions

File tree

‎packages/app/e2e/regression/settings-wsl.spec.ts‎

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,91 @@
11
import { base64Encode } from "@opencode/util/encode"
2-
import { expect, test } from "@playwright/test"
2+
import { expect, test, type Locator } from "@playwright/test"
33
import { NO_PROVIDER, REMOTE_SERVER, SERVER, holdRoute, project, provider, session } from "../utils/app"
44
import { mockOpenCodeServer, mockServers } from "../utils/mock-server"
55
import { expectSessionTitle } from "../utils/waits"
66

77
test.use({ viewport: { width: 1280, height: 900 } })
88

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+
989
for (const mode of ["failed", "stopped", "ready"] as const) {
1090
test(`manages a ${mode} configured WSL server from the Servers page`, async ({ page }) => {
1191
await mockOpenCodeServer(page, {

‎packages/app/e2e/utils/settings-wsl.fixture.tsx‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export function mount(input: {
2929
ssh?: string | null
3030
storage?: string | null
3131
hold?: string | null
32+
/** Comma-separated installed distributions for the add-server dialog. */
33+
distros?: string | null
34+
/** Holds the distribution refresh job while inspecting disabled dialog controls. */
35+
busy?: string | null
3236
/** Enables the updater Ipc; check and install reject with this message, which may be empty. */
3337
updater?: string | null
3438
}) {
@@ -40,6 +44,7 @@ export function mount(input: {
4044
const endpoint = { url: input.wsl ?? input.server }
4145
const ready = () => ({ kind: "ready" as const, url: endpoint.url, password: null })
4246
const held = Promise.withResolvers<void>()
47+
const distros = input.distros?.split(",").filter(Boolean) ?? []
4348

4449
const storage = (name?: string) => {
4550
const item = (key: string) => (name ? `${name}:${key}` : key)
@@ -82,11 +87,18 @@ export function mount(input: {
8287
},
8388
state: {
8489
runtime: { available: true, version: "2", error: null },
85-
installed: [],
86-
online: [],
87-
distroProbes: {},
90+
installed: distros.map((name) => ({ name, version: name === "Debian-WSL1" ? 1 : 2, isDefault: false })),
91+
online: distros.length
92+
? ["Debian", "FedoraLinux-43", "openSUSE-Tumbleweed", "OracleLinux_9_1", "kali-linux"].map((name) => ({
93+
name,
94+
label: name,
95+
}))
96+
: [],
97+
distroProbes: Object.fromEntries(
98+
distros.map((name) => [name, { name, canExecute: true, hasBash: true, hasCurl: true, error: null }]),
99+
),
88100
pendingRestart: false,
89-
hostJob: "idle",
101+
hostJob: input.busy ? "busy" : "idle",
90102
distroJobs: {},
91103
servers: [
92104
{
@@ -101,6 +113,19 @@ export function mount(input: {
101113
},
102114
],
103115
opencodeChecks: {
116+
...Object.fromEntries(
117+
distros.map((name) => [
118+
name,
119+
{
120+
distro: name,
121+
resolvedPath: null,
122+
version: null,
123+
expectedVersion: "current",
124+
matchesDesktop: null,
125+
error: null,
126+
},
127+
]),
128+
),
104129
Ubuntu: {
105130
distro: "Ubuntu",
106131
resolvedPath: "/usr/bin/opencode",

‎packages/app/e2e/utils/settings-wsl.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
ssh: query.get("ssh"),
1919
storage: query.get("storage"),
2020
hold: query.get("hold"),
21+
distros: query.get("distros"),
22+
busy: query.get("busy"),
2123
updater: query.get("updater"),
2224
})
2325
</script>

‎packages/gui-plugins/src/wsl/dialog.css‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@
187187
width: 100%;
188188
}
189189

190-
.settings-wsl-distro-group [data-slot="radio-v2-items"] {
190+
.settings-wsl-distro-group[data-component="radio-v2"] [data-slot="radio-v2-items"] {
191191
width: 100%;
192192
gap: 0;
193193
}
194194

195-
.settings-wsl-distro-row {
195+
.settings-wsl-distro-row[data-slot="radio-v2-item"] {
196196
box-sizing: border-box;
197197
width: 100%;
198198
min-height: 62px;
@@ -375,7 +375,7 @@
375375
width: 100%;
376376
}
377377

378-
.settings-wsl-catalog-row {
378+
.settings-wsl-catalog-row[data-slot="radio-v2-item"] {
379379
min-height: 48px;
380380
}
381381

0 commit comments

Comments
 (0)