gui: the SOCKS login fields speak Traditional Chinese, and their test runs in every language (#852)
#852 added "Proxy address", "Username (optional)" and "Password (optional)" in en, zh, ja and de, but not in zh-TW, so a zh-TW user saw English labels beside the proxy. They are now 代理位址, 使用者名稱(選填) and 密碼(選填), in the words zh-TW already uses (位址, 儲存). settings-proxy-auth.test.cjs ran only en and zh. It now runs en, zh, zh-TW, ja and de, each looking up its own labels and its own "Saved". Run: settings-proxy-auth 10/10 (chromium + webkit x 5 languages, at 1100, 560 and 375 px); go test -tags nogui ./internal/gui ok. Break-check: with the zh-TW strings taken out, chromium zh-TW goes red and the other four pass.
This commit is contained in:
@@ -5293,6 +5293,9 @@ const I18N = {
|
||||
"A closed panel or window frees about 100 MB after a minute; opening it loads it again": "面板或視窗關閉一分鐘後釋放約 100 MB,再次開啟時重新載入",
|
||||
"With window": "跟隨視窗",
|
||||
"Proxy": "代理",
|
||||
"Proxy address": "代理位址",
|
||||
"Username (optional)": "使用者名稱(選填)",
|
||||
"Password (optional)": "密碼(選填)",
|
||||
"Requests to vendors without a proxy of their own, and update checks, go through {proxy}": "未單獨設定代理的模型廠商請求和檢查更新都經由 {proxy}",
|
||||
"Following the system proxy, {proxy}": "跟隨系統代理:{proxy}",
|
||||
"Following HTTPS_PROXY, {proxy}": "跟隨 HTTPS_PROXY:{proxy}",
|
||||
|
||||
@@ -40,8 +40,17 @@ function server(lang, posts, proxy = "") {
|
||||
};
|
||||
}
|
||||
|
||||
const labels = {
|
||||
en: { user: "Username (optional)", pass: "Password (optional)", custom: "Custom", save: "Save", off: "Off", auto: "Auto", saved: "Saved" },
|
||||
zh: { user: "用户名(可选)", pass: "密码(可选)", custom: "自定义", save: "保存", off: "关闭", auto: "自动", saved: "已保存" },
|
||||
"zh-TW": { user: "使用者名稱(選填)", pass: "密碼(選填)", custom: "自定義", save: "儲存", off: "關閉", auto: "自動", saved: "已儲存" },
|
||||
ja: { user: "ユーザー名(任意)", pass: "パスワード(任意)", custom: "カスタム", save: "保存", off: "オフ", auto: "自動", saved: "保存しました" },
|
||||
de: { user: "Benutzername (optional)", pass: "Passwort (optional)", custom: "Benutzerdefiniert", save: "Speichern", off: "Aus", auto: "Automatisch", saved: "Gespeichert" },
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh"]) {
|
||||
for (const lang of Object.keys(labels)) {
|
||||
const l = labels[lang];
|
||||
test(`${engine} ${lang}: optional SOCKS credentials in settings`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
@@ -54,19 +63,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await page.goto("http://magpie.test/?view=settings&tab=network");
|
||||
const box = page.locator("#proxySegs");
|
||||
const address = box.locator("input.proxy");
|
||||
const user = box.getByRole("textbox", { name: lang === "zh" ? "用户名(可选)" : "Username (optional)", exact: true });
|
||||
const pass = box.getByLabel(lang === "zh" ? "密码(可选)" : "Password (optional)", { exact: true });
|
||||
const user = box.getByRole("textbox", { name: l.user, exact: true });
|
||||
const pass = box.getByLabel(l.pass, { exact: true });
|
||||
const saved = async (action, want) => {
|
||||
const count = posts.length;
|
||||
const response = page.waitForResponse((r) => r.url().endsWith("/api/settings") && r.request().method() === "POST");
|
||||
await action();
|
||||
await response;
|
||||
await page.waitForFunction(() => document.querySelector("#status")?.textContent.includes("Saved") || document.querySelector("#status")?.textContent.includes("已保存"));
|
||||
await page.waitForFunction((word) => document.querySelector("#status")?.textContent.includes(word), l.saved);
|
||||
assert.equal(posts.length, count + 1, "save once for the whole proxy");
|
||||
assert.equal(posts.at(-1).proxy, want);
|
||||
};
|
||||
|
||||
await box.getByRole("button", { name: lang === "zh" ? "自定义" : "Custom", exact: true }).click();
|
||||
await box.getByRole("button", { name: l.custom, exact: true }).click();
|
||||
await address.fill("socks5://127.0.0.1:1080");
|
||||
await user.fill("a@b:/% 用户");
|
||||
await user.press("Tab");
|
||||
@@ -122,7 +131,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await address.fill("socks5://name:p%FFss@127.0.0.1:1080");
|
||||
assert.equal(await address.inputValue(), "socks5://127.0.0.1:1080");
|
||||
assert.equal(await pass.inputValue(), "p%FFss");
|
||||
await saved(() => box.getByRole("button", { name: lang === "zh" ? "保存" : "Save", exact: true }).click(), "socks5://name:p%FFss@127.0.0.1:1080");
|
||||
await saved(() => box.getByRole("button", { name: l.save, exact: true }).click(), "socks5://name:p%FFss@127.0.0.1:1080");
|
||||
|
||||
// HTTP and bare addresses still work; a hidden SOCKS login isn't attached.
|
||||
await address.fill("http://127.0.0.1:7890");
|
||||
@@ -134,8 +143,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await address.fill("socks5://127.0.0.1:1080");
|
||||
await user.fill("unsaved-user");
|
||||
await pass.fill("unsaved-password");
|
||||
await saved(() => box.getByRole("button", { name: lang === "zh" ? "关闭" : "Off", exact: true }).click(), "direct");
|
||||
await saved(() => box.getByRole("button", { name: lang === "zh" ? "自动" : "Auto", exact: true }).click(), "");
|
||||
await saved(() => box.getByRole("button", { name: l.off, exact: true }).click(), "direct");
|
||||
await saved(() => box.getByRole("button", { name: l.auto, exact: true }).click(), "");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user