fix(settings): align the HTTP Proxy form (#4863)

fix(settings): align the HTTP Proxy form
This commit is contained in:
l0ng-ai
2026-11-21 07:19:48 +08:00
committed by GitHub
parent c0e888dd2f
commit 8b3f55dfb4
3 changed files with 150 additions and 93 deletions
+95
View File
@@ -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([]);
});
@@ -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;
+42 -64
View File
@@ -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<ProxySettingsValid>) =
return [proxy, update];
}
function Radio({
name,
checked,
onSelect,
label,
disabled,
}: {
name: string;
checked: boolean;
onSelect: () => void;
label: string;
disabled?: boolean;
}) {
return (
<label className={clsx(styles.radio, disabled && styles.disabled)}>
<input type="radio" name={name} checked={checked} disabled={disabled} onChange={onSelect} />
<SearchLabel text={label} />
</label>
);
}
function ProxyOptions() {
const [proxy, update] = useProxy();
const name = useId();
@@ -88,10 +67,11 @@ function ProxyOptions() {
{MODES.map((m) => (
<div key={m.value}>
<Radio
className={styles.radioRow}
name={name}
checked={proxy.mode === m.value}
onSelect={() => update({ mode: m.value })}
label={m.label}
onChange={() => update({ mode: m.value })}
label={<SearchLabel text={m.label} />}
/>
{m.hint && (
<div className={styles.hint}>
@@ -106,52 +86,50 @@ function ProxyOptions() {
{KINDS.map((k) => (
<Radio
key={k.value}
className={styles.radioRow}
name={kindName}
checked={proxy.kind === k.value}
disabled={!manual}
onSelect={() => update(withProxyKind(proxy, k.value))}
label={k.label}
onChange={() => update(withProxyKind(proxy, k.value))}
label={<SearchLabel text={k.label} />}
/>
))}
</div>
<div className={styles.hostRow}>
<FormGroup>
<Row label="Host name" htmlFor={ids.host}>
<Input
id={ids.host}
className={styles.host}
className={styles.field}
disabled={!manual}
value={proxy.host}
onChange={(e) => update({ host: e.target.value })}
/>
</Row>
<Row label="Port number" htmlFor={ids.port}>
{manual ? (
<NumberInput
id={ids.port}
value={proxy.port}
onChange={(port) => update({ port })}
{...PROXY_PORT_LIMITS}
integer
aria-label="Port number"
/>
) : (
<Input id={ids.port} className={styles.port} value={String(proxy.port)} disabled readOnly />
)}
<NumberInput
id={ids.port}
value={proxy.port}
onChange={(port) => update({ port })}
{...PROXY_PORT_LIMITS}
integer
disabled={!manual}
aria-label="Port number"
/>
</Row>
</div>
<Row
label="No proxy for"
htmlFor={ids.noProxy}
hint="Comma-separated host names; * matches any characters, e.g. *.example.com, 192.168.*"
>
<Input
id={ids.noProxy}
className={styles.wide}
disabled={!manual}
value={proxy.noProxy}
onChange={(e) => update({ noProxy: e.target.value })}
/>
</Row>
<Row
label="No proxy for"
htmlFor={ids.noProxy}
hint="Comma-separated host names; * matches any characters, e.g. *.example.com, 192.168.*"
>
<Input
id={ids.noProxy}
className={styles.field}
disabled={!manual}
value={proxy.noProxy}
onChange={(e) => update({ noProxy: e.target.value })}
/>
</Row>
</FormGroup>
<div className={styles.toggle}>
<Checkbox
checked={proxy.authenticate}
@@ -160,11 +138,11 @@ function ProxyOptions() {
label={<SearchLabel text="Proxy authentication" />}
/>
</div>
<div className={styles.auth}>
<FormGroup indented>
<Row label="Login" htmlFor={ids.login}>
<Input
id={ids.login}
className={styles.host}
className={styles.field}
disabled={!auth}
value={proxy.login}
onChange={(e) => update({ login: e.target.value })}
@@ -174,19 +152,19 @@ function ProxyOptions() {
<Input
id={ids.password}
type="password"
className={styles.host}
className={styles.field}
disabled={!auth}
value={proxy.password}
onChange={(e) => update({ password: e.target.value })}
/>
</Row>
</div>
{problem && (
<div className={styles.error} role="alert">
<T>{problem}</T>
</div>
)}
</FormGroup>
</div>
{problem && (
<div className={styles.error} role="alert">
<T>{problem}</T>
</div>
)}
<CheckConnection proxy={proxy} />
</div>
);