From 8b3f55dfb40f4012dd3e8b936ece93bbe799a73c Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Sat, 21 Nov 2026 07:19:48 +0800 Subject: [PATCH] fix(settings): align the HTTP Proxy form (#4863) fix(settings): align the HTTP Proxy form --- e2e/httpProxySettingsLayout.spec.ts | 95 ++++++++++++++++ .../settings/pages/HttpProxy.module.css | 42 +++---- src/features/settings/pages/httpProxy.tsx | 106 +++++++----------- 3 files changed, 150 insertions(+), 93 deletions(-) create mode 100644 e2e/httpProxySettingsLayout.spec.ts diff --git a/e2e/httpProxySettingsLayout.spec.ts b/e2e/httpProxySettingsLayout.spec.ts new file mode 100644 index 000000000..8bb0d5238 --- /dev/null +++ b/e2e/httpProxySettingsLayout.spec.ts @@ -0,0 +1,95 @@ +import type { Page } from "@playwright/test"; +import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; + +async function openProxySettings(page: Page) { + await page.keyboard.press("Meta+,"); + const dialog = page.getByRole("dialog", { name: "Settings", exact: true }); + const search = dialog.getByRole("textbox", { name: "Search settings" }); + await search.fill("HTTP Proxy"); + await dialog.getByRole("treeitem", { name: "HTTP Proxy", exact: true }).click(); + await search.clear(); + return dialog; +} + +test("HTTP Proxy keeps server and authentication fields aligned in narrow settings", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1120, height: 740 }); + const dialog = await openProxySettings(page); + const auto = dialog.getByRole("radio", { name: "Auto-detect proxy settings", exact: true }); + const manual = dialog.getByRole("radio", { name: "Manual proxy configuration", exact: true }); + const host = dialog.getByRole("textbox", { name: "Host name:", exact: true }); + const port = dialog.getByRole("textbox", { name: /^Port number:?$/ }); + const exceptions = dialog.getByRole("textbox", { name: "No proxy for:", exact: true }); + const auth = dialog.getByRole("checkbox", { name: "Proxy authentication", exact: true }); + const login = dialog.getByRole("textbox", { name: "Login:", exact: true }); + const password = dialog.getByLabel("Password", { exact: true }); + await expect(auto).toBeChecked(); + for (const control of [host, port, exceptions, auth, login, password]) await expect(control).toBeDisabled(); + + await auto.press("ArrowDown"); + await expect(manual).toBeChecked(); + await host.fill("127.0.0.1"); + await expect(login).toBeDisabled(); + await auth.check(); + await login.fill("layout-user"); + await password.fill("layout-password"); + + for (const width of [1120, 580, 520]) { + await page.setViewportSize({ width, height: 740 }); + for (const control of [host, port, exceptions, login, password]) { + await expect(control).toBeInViewport({ ratio: 1 }); + } + const [hostBox, portBox, exceptionsBox, loginBox, passwordBox] = await Promise.all( + [host, port, exceptions, login, password].map((control) => control.boundingBox()), + ); + if (!hostBox || !portBox || !exceptionsBox || !loginBox || !passwordBox) { + throw new Error("Missing HTTP Proxy field bounds"); + } + expect(hostBox.y).toBeLessThan(portBox.y); + expect(portBox.y).toBeLessThan(exceptionsBox.y); + expect(hostBox.x).toBeCloseTo(portBox.x, 0); + expect(hostBox.x).toBeCloseTo(exceptionsBox.x, 0); + expect(hostBox.width).toBeCloseTo(exceptionsBox.width, 0); + expect(loginBox.x).toBeCloseTo(passwordBox.x, 0); + expect(loginBox.width).toBeCloseTo(passwordBox.width, 0); + } + + await auto.check(); + await expect(password).toBeDisabled(); + await manual.check(); + await expect(host).toHaveValue("127.0.0.1"); + await expect(login).toHaveValue("layout-user"); + await expect(password).toHaveValue("layout-password"); +}); + +test("HTTP Proxy checks a URL with the staged manual settings in a narrow window", async ({ workbench: page }) => { + await page.setViewportSize({ width: 540, height: 680 }); + await stubDesktop(page); + await page.evaluate(() => { + window.__ipc.handlers.proxy_check_connection = () => "200 OK"; + }); + const dialog = await openProxySettings(page); + const check = dialog.getByRole("button", { name: "Check connection…", exact: true }); + const manual = dialog.getByRole("radio", { name: "Manual proxy configuration", exact: true }); + await manual.check(); + await expect(check).toBeDisabled(); + await dialog.getByRole("textbox", { name: "Host name:", exact: true }).fill("proxy.example.test"); + const port = dialog.getByRole("textbox", { name: /^Port number:?$/ }); + await port.fill("8079"); + await port.press("ArrowUp"); + await expect(port).toHaveValue("8080"); + await check.click(); + const target = page.getByRole("textbox", { name: "Enter any URL to check connection to:", exact: true }); + const submit = page.getByRole("button", { name: "Check", exact: true }); + await target.fill("http://example.test/health"); + await expect(target).toBeInViewport({ ratio: 1 }); + await expect(submit).toBeInViewport({ ratio: 1 }); + await submit.click(); + await expect(page.getByRole("status").filter({ hasText: "Connection successful: 200 OK" })).toBeVisible(); + expect(await ipcCalls(page, "proxy_check_connection")).toEqual([ + { + proxy: expect.objectContaining({ mode: "manual", kind: "http", host: "proxy.example.test", port: 8080 }), + url: "http://example.test/health", + }, + ]); + expect(await ipcCalls(page, "settings_set")).toEqual([]); +}); diff --git a/src/features/settings/pages/HttpProxy.module.css b/src/features/settings/pages/HttpProxy.module.css index 3609c3846..5362d841c 100644 --- a/src/features/settings/pages/HttpProxy.module.css +++ b/src/features/settings/pages/HttpProxy.module.css @@ -7,45 +7,30 @@ display: flex; flex-direction: column; } -.radio { - display: inline-flex; - align-items: center; - gap: var(--space-1-5); - min-height: 28px; -} -.radio input { - margin: 0; - accent-color: var(--accent); -} -.disabled { - color: var(--fg-subtle); +.radioRow { + min-height: var(--h-field); } .hint { - padding-left: 20px; + padding-inline-start: calc(16px + var(--space-2)); color: var(--fg-subtle); + font-size: var(--fs-small); + line-height: 1.4; } /* Manual configuration, indented under its radio button. */ .manual { display: flex; flex-direction: column; - padding-left: 20px; + padding-inline-start: calc(16px + var(--space-2)); } .kinds { display: flex; align-items: center; + flex-wrap: wrap; gap: var(--space-4); } -.hostRow { - display: flex; - align-items: flex-start; - gap: 24px; -} -.host { - width: 220px; -} -.port { - width: 64px; +.field { + width: 100%; } .wide { width: 360px; @@ -55,11 +40,6 @@ align-items: center; min-height: 28px; } -.auth { - display: flex; - flex-direction: column; - padding-left: 20px; -} .error { color: var(--danger); } @@ -82,6 +62,10 @@ align-items: center; gap: var(--space-2); } +.urlRow > input { + flex: 1; + min-width: 0; +} .result { min-height: 1lh; overflow-wrap: anywhere; diff --git a/src/features/settings/pages/httpProxy.tsx b/src/features/settings/pages/httpProxy.tsx index c775c5424..992de3a07 100644 --- a/src/features/settings/pages/httpProxy.tsx +++ b/src/features/settings/pages/httpProxy.tsx @@ -15,8 +15,8 @@ import { type ProxyModeValid, type ProxySettingsValid, } from "@/platform/proxySettings"; -import { Button, Checkbox, Input, Popup, T } from "@/ui"; -import { NumberInput, Row, SearchLabel } from "../components/Form"; +import { Button, Checkbox, Input, Popup, Radio, T } from "@/ui"; +import { FormGroup, NumberInput, Row, SearchLabel } from "../components/Form"; import { usePageContext, useSetting } from "../components/context"; import { stage } from "../model/staging"; import type { PageSpec } from "./spec"; @@ -47,27 +47,6 @@ function useProxy(): [ProxySettingsValid, (patch: Partial) = return [proxy, update]; } -function Radio({ - name, - checked, - onSelect, - label, - disabled, -}: { - name: string; - checked: boolean; - onSelect: () => void; - label: string; - disabled?: boolean; -}) { - return ( - - ); -} - function ProxyOptions() { const [proxy, update] = useProxy(); const name = useId(); @@ -88,10 +67,11 @@ function ProxyOptions() { {MODES.map((m) => (
update({ mode: m.value })} - label={m.label} + onChange={() => update({ mode: m.value })} + label={} /> {m.hint && (
@@ -106,52 +86,50 @@ function ProxyOptions() { {KINDS.map((k) => ( update(withProxyKind(proxy, k.value))} - label={k.label} + onChange={() => update(withProxyKind(proxy, k.value))} + label={} /> ))}
-
+ update({ host: e.target.value })} /> - {manual ? ( - update({ port })} - {...PROXY_PORT_LIMITS} - integer - aria-label="Port number" - /> - ) : ( - - )} + update({ port })} + {...PROXY_PORT_LIMITS} + integer + disabled={!manual} + aria-label="Port number" + /> -
- - update({ noProxy: e.target.value })} - /> - + + update({ noProxy: e.target.value })} + /> + +
} />
-
+ update({ login: e.target.value })} @@ -174,19 +152,19 @@ function ProxyOptions() { update({ password: e.target.value })} /> -
- {problem && ( -
- {problem} -
- )} +
+ {problem && ( +
+ {problem} +
+ )} );