diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 936a9a6ac..d4af3a7d3 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -4020,7 +4020,11 @@ input.words.search-key, input.words.search-url { flex: 1 1 120px; width: auto; m .prefs .val.searcher-then-list > .rt-cond { min-width: 0; max-width: 100%; } .searcher-then-n { color: var(--muted); font-variant-numeric: tabular-nums; } .side-effort .effort-ic svg { width: 100%; height: 100%; } -.row.pref.lan-address-row { position: relative; height: 50px; transition: height .28s var(--ease); } +/* its controls are placed in a fixed height, so it stays border-box where + Settings' other rows go content-box (a pointer that hovers): there the + padding was added under it, a blank band below the address (the owner, + 11-08). 51, as tall as the rows around it. */ +.row.pref.lan-address-row, #view-settings .row.pref.lan-address-row { position: relative; box-sizing: border-box; height: 51px; transition: height .28s var(--ease); } .row.pref.lan-address-row .who { position: absolute; top: 16px; left: 14px; } .prefs .lan-address-row .val { max-width: 64%; } /* Browser access: a link per address, each with its copy button */ @@ -4045,7 +4049,7 @@ input.words.search-key, input.words.search-url { flex: 1 1 120px; width: auto; m .pop.proto-menu.lan-address-menu { width: min(320px, calc(100vw - 16px)); max-height: min(360px, 70vh); overflow-y: auto; } .lan-address-menu .pm-name { font: var(--code-style, normal) var(--code-weight, 400) 12px var(--code-font, var(--code)); font-stretch: var(--code-stretch, 100%); } @media (max-width: 600px) { - .row.pref.lan-address-row { height: 76px; } + .row.pref.lan-address-row, #view-settings .row.pref.lan-address-row { height: 81px; } /* 13 under its second line, as over its first */ .lan-address-controls .segs { right: 12px; } .row.pref .proto.pick.lan-interface { top: 44px; } .lan-address-controls .lan-address-text { top: 47px; } diff --git a/internal/gui/tests/lan-address-height.test.cjs b/internal/gui/tests/lan-address-height.test.cjs new file mode 100644 index 000000000..7e69ad895 --- /dev/null +++ b/internal/gui/tests/lan-address-height.test.cjs @@ -0,0 +1,85 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Settings › Network: Share on local network's Address row is as tall as its +// controls, with the same room above them as below (the owner, 11-08: a +// blank band under the address made the card's spacing uneven). With a +// pointer that hovers, Settings' rows are content-box, and the row's fixed +// height had the padding added under it. One address and several, wide and +// narrow, Chromium and WebKit, English and Chinese. +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 { watchSettingsReads, settingsDrawn } = require("./reader.cjs"); + +const assets = path.resolve(__dirname, "../assets"); + +function server(lang, lanURLs) { + const s = { + theme: "light", lang, tray: "panel", currency: "usd", proxy: "", redactWords: [], + version: "0.1.400", dir: "/config/magpie", gateway: "http://0.0.0.0:3425", proxyNow: "none", proxySource: "none", + visionModels: [], imageGenModels: [], workbuddyCheckins: [], + lan: true, lanKey: "sk-magpie-0123456789abcdef", lanURLs, lanPublic: [], + fx: { rate: 7.2, at: new Date().toISOString(), stale: false }, + }; + return async (route) => { + const url = new URL(route.request().url()); + const json = (data) => route.fulfill({ json: data }); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" }, fx: s.fx }); + if (url.pathname === "/api/settings") return json(s); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/usage/quotas") return json([]); + if (url.pathname === "/api/groups") return json({ groups: [], models: [] }); + 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 route.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(engine + ": the LAN address row is as tall as its controls", async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + for (const lang of ["en", "zh"]) { + for (const urls of [["http://10.0.0.175:3425"], ["http://10.0.0.175:3425", "http://192.168.1.5:3425"]]) { + for (const width of [1300, 560]) { + const what = `${lang} ${urls.length} address(es) at ${width}px`; + await t.test(what, async () => { + const ctx = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" }); + const page = await ctx.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, urls)); + await watchSettingsReads(page); + await page.goto("http://localhost:3430/?view=settings&tab=network"); + await settingsDrawn(page); + await page.locator("#lanList .lan-address-row .lan-copy button").waitFor(); + const m = await page.evaluate(() => { + const rows = [...document.querySelectorAll("#lanList > .row")]; + const r = document.querySelector("#lanList .lan-address-row"); + const rb = r.getBoundingClientRect(); + const parts = [...r.querySelectorAll(".lan-address-controls > *, .who")].map((e) => e.getBoundingClientRect()).filter((b) => b.height); + return { + hover: matchMedia("(hover: hover)").matches, + share: rows[0].getBoundingClientRect().height, row: rb.height, + above: Math.min(...parts.map((b) => b.top)) - rb.top, + below: rb.bottom - Math.max(...parts.map((b) => b.bottom)), + }; + }); + const at = what + ": " + JSON.stringify(m); + assert.ok(m.hover, "the page has a pointer that hovers, where the rows are content-box: " + at); + assert.ok(Math.abs(m.above - m.below) <= 2, "as much room below the controls as above: " + at); + if (width > 600) assert.ok(Math.abs(m.row - m.share) <= 1, "as tall as the row above it: " + at); + assert.deepEqual(errors, []); + await ctx.close(); + }); + } + } + } + }); +}