A Mac set to English with Japan as its region (AppleLocale en_JP, 24 hours) showed 12 hours: with neither AppleICUForce24HourTime nor AppleICUForce12HourTime set, the page formatted in WKWebView's navigator.language (en-US). boot.js now carries the system's own tag as "locale" (macOS: `defaults read -g AppleLocale`, with @rg= winning; Windows: Control Panel\International LocaleName; Linux: LC_ALL, LC_TIME, LANG), and intlLang takes it over navigator.language for English. The two forced clock switches still win over the region's clock. A browser tab keeps its own locale. Run (mica): go test -run 'HourCycle|LocaleTag|Boot' ./internal/gui ok; gofmt -l clean; go vet darwin, linux nogui, windows on internal/gui clean; GUI hc-clock, reset-clock-formats, dates-gui-lang, i18n-keys, header-relang, desktop-lang in chromium and webkit: 0 fail. Real AppleLocale on this Mac reads en_SG. Broken by hand: intlLang back to navigator.language turns the new en-JP case red in both engines. Not tried: a real Windows or Linux session with a regional format that differs from the display language; full suite starts after the tag.
67 lines
3.8 KiB
JavaScript
67 lines
3.8 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The clock the system is set to (boot.js hourCycle) reaches every time the
|
|
// GUI shows: an en-US Mac set to 24 hours showed 12 (iXerol on X), and a
|
|
// 12-hour system showed the GUI's fixed 24.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
|
|
function serve(hc, loc) {
|
|
return async (r) => {
|
|
const url = new URL(r.request().url());
|
|
const json = (data) => r.fulfill({ json: data });
|
|
const boot = `window.bootPrefs = {lang:"en",theme:"light",web:false${hc ? `,hourCycle:"${hc}"` : ""}${loc ? `,locale:"${loc}"` : ""}};`;
|
|
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: boot });
|
|
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang: "en", theme: "light" } });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
await r.fulfill({ body: await fs.readFile(file), contentType });
|
|
};
|
|
}
|
|
|
|
const cases = [
|
|
// the region says 12 hours; the system says 24
|
|
{ hc: "h23", locale: "en-US", plain: "15:05", fixed: "15:05" },
|
|
// the region says 24 hours; the system says 12
|
|
{ hc: "h12", locale: "en-GB", plain: "3:05", fixed: "3:05" },
|
|
// the system says nothing: the region's own, and the GUI's 24-hour places
|
|
{ hc: "", locale: "en-US", plain: "3:05", fixed: "15:05" },
|
|
// no override, a webview saying en-US, and a Mac whose region is Japan
|
|
// (AppleLocale en_JP): the system's tag decides, 24 hours (iXerol on X)
|
|
{ hc: "", locale: "en-US", sys: "en-JP", plain: "15:05", fixed: "15:05" },
|
|
];
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const c of cases) {
|
|
test(`${engine} ${c.locale} system ${c.hc || "silent"}: times follow the system's clock`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await (await browser.newContext({ locale: c.locale, timezoneId: "UTC", viewport: { width: 1100, height: 800 } })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(c.hc, c.sys));
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForFunction(() => typeof intlLang === "function");
|
|
const out = await page.evaluate(() => {
|
|
const at = new Date(Date.UTC(2026, 9, 12, 15, 5, 7));
|
|
return {
|
|
plain: at.toLocaleTimeString(intlLang(), { hour: "2-digit", minute: "2-digit" }),
|
|
fixed: at.toLocaleTimeString(intlLang(), { hour: "2-digit", minute: "2-digit", ...hourClock() }),
|
|
};
|
|
});
|
|
if (c.hc === "h12") { assert.match(out.plain, /3:05/); assert.match(out.plain, /pm/i); assert.match(out.fixed, /pm/i); }
|
|
if (c.hc === "h23") { assert.match(out.plain, /^15:05/); assert.match(out.fixed, /^15:05/); }
|
|
if (c.sys === "en-JP") { assert.match(out.plain, /^15:05/); assert.equal(await page.evaluate(() => intlLang()), "en-JP"); }
|
|
else if (c.hc === "") { assert.match(out.plain, /3:05.*pm/i); assert.match(out.fixed, /^15:05/); }
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|