On a phone, magpie web's pages sat in a strip under the header that scrolled sideways, with nothing to show that more pages lay past its edge. Agents, Library and the rest looked missing. The pages are now a tab bar at the foot, as an iPhone app's (HIG): each tab its mark over its word, the page open marked. Five tabs at most: with more pages than that, the fifth is More, and its menu lists the rest with their marks and a tick on the open one. More is marked while one of them is open, and it carries the dot when one of them has one. phonetabs.js does this. app.js loads it lazily only on a phone, so the core script doesn't grow. A status line comes up over the bar. The bar is only for the window, never the tray panel (body.panel). Agents still isn't shown in gateway mode on a machine with no agents, as designed (Settings > General > Gateway mode brings it back). Library has been shown in gateway mode sincef285426ac. Tests: phone-tabs.test.cjs (new) runs at 390x844 in chromium and webkit, in en, zh, zh-TW, ja and de, with gateway mode on and off. It checks: - five tabs with More fifth, at the foot, 44px tall; - nothing scrolls sideways; - every page is reached from the bar or from More, and More's menu opens above the bar; - the bar covers no page content and no status line; - a desktop browser has no More. reader.cjs gets openPage() (the tab, or More's menu). mobile-web, phone-no-sideways, routing-held-dot and name-suffix-saved open pages through it. phone-web checks the bar at the foot. old-webkit lists phonetabs.js as lazy. market-more waits for the view's own foot, not the window's, which is now above the bar. group-from-model-add wheels Add wholly into the view before its press, because at 600x420 WebKit took a press on Add's half-hidden middle as one on the header. Run on mote: - The whole GUI suite once (450 files, concurrency 3). 33 red files were then run on this change's base and on the branch. The reds only on the branch were the four tests that tapped tabs now under More, phone-web's old label check, market-more, group-from-model-add (webkit 600x420), and the panel tests agent-menu-label, zcode-models and panel-fit-tabs (webkit). The panel tests are web:true at 360-380px, so the bar's padding reached the panel. It is now scoped :not(.panel). - After the fixes: phone-web, market-more, group-from-model-add, agent-menu-label, zcode-models, panel-fit-tabs, phone-tabs, mobile-web, phone-no-sideways, routing-held-dot, name-suffix-saved, old-webkit and i18n-keys. All are green except reds already filed on main: #5919 (old-webkit :has), #5869 (phone-no-sideways de 375) and #5215 (tray-cell-click, a web:false panel test). mobile-web's 900/1280 desktop screenshots need git, so they were run with BASE_REF set to a commit of the base's assets: 30/30 pass in both engines, so the desktop is unchanged. - gofmt, go vet for darwin, linux (nogui) and windows, and go test ./internal/gui. - Again at the pushed head, rebased on origin/mainca7a39291: the 13 GUI files above (239 pass; reds only #5919, #5869 and mobile-web's git-less desktop compare), gofmt, vet on all three, and go test ./internal/gui ok. TestCoreScriptBudget was over at the old base662546e78and passes here: app.js is ~430 bytes smaller. - Rebased again on388ca9ad4(two agent commits touching app.js and i18n.js): the budget tests, i18n-keys, phone-tabs and phone-web pass (34 of 34). Then onto0baa223ec(Kun; a one-line app.js change) with no further run before the push. Broken by hand: - Without layoutNav's import of phonetabs.js, phone-tabs is 20 of 24 red. - Without :not(.panel), panel-fit-tabs (webkit, 5 languages) and agent-menu-label go red. Not tried: a real iPhone's Safari, or the LAN share opened on a real phone.
159 lines
10 KiB
JavaScript
159 lines
10 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// magpie web on a phone (geraldpppppp on X: 优化移动端 UI,为什么看不到agent
|
|
// 以及资源库之类的那些入口?). The pages were a strip that scrolled sideways
|
|
// with nothing saying it did, and Agents and the Library lay past its edge.
|
|
// Now they are a tab bar at the window's foot, as an iPhone app's: five tabs,
|
|
// the fifth More when more pages show, its menu the rest with their icons.
|
|
// Every page is a tap or two away, the bar covers no part of a page or its
|
|
// status line, and nothing scrolls sideways. In gateway mode (Agents left
|
|
// out) and with every page; in every language; at 390px.
|
|
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");
|
|
const LANGS = { en: "More", zh: "更多", "zh-TW": "更多", ja: "その他", de: "Mehr" };
|
|
|
|
function serve(lang, gateway) {
|
|
const providers = { providers: [], presets: [], excluded: [], gateway: { running: true, window: true } };
|
|
const state = { agents: [], profiles: [], settings: { lang, theme: "light", redact: true } };
|
|
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:${JSON.stringify(lang)},theme:"light",web:true${gateway ? ",gateway:true" : ""}};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/providers") return json(providers);
|
|
if (url.pathname === "/api/settings") return json({ lang, theme: "light", web: true, gatewayOn: gateway, gatewayWhy: gateway ? "no-agents" : "" });
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/plugins/market") return json({ listings: [], state: { bun: true, bunVersion: "1.3.0", plugins: [], picker: false } });
|
|
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)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
async function open(browser, lang, gateway, view) {
|
|
const context = await browser.newContext({ viewport: { width: 390, height: 844 }, deviceScaleFactor: 2, hasTouch: true, isMobile: browser.browserType().name() === "chromium", reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
page.errors = [];
|
|
page.on("pageerror", (e) => page.errors.push(e.message));
|
|
await page.route("**/*", serve(lang, gateway));
|
|
await page.goto("http://magpie.test/" + (view ? "?view=" + view : ""));
|
|
await page.waitForSelector("#nav", { state: "visible" });
|
|
await page.waitForFunction(() => document.querySelector("#nav .nav-more") || document.querySelectorAll("#nav > button[data-view]").length);
|
|
await page.waitForTimeout(300);
|
|
return page;
|
|
}
|
|
|
|
// the tabs the bar shows, in order, each with its box
|
|
const tabs = (page) => page.$$eval("#nav > button", (bs) => bs.filter((b) => {
|
|
const r = b.getBoundingClientRect();
|
|
return getComputedStyle(b).display !== "none" && r.width > 0 && r.height > 0;
|
|
}).map((b) => {
|
|
const r = b.getBoundingClientRect();
|
|
return { view: b.dataset.view || "more", on: b.classList.contains("on"), x: r.x, y: r.y, w: r.width, h: r.height, label: b.textContent.trim() };
|
|
}));
|
|
// every page the reader may open: the nav's buttons that a phone's bar or its More list carries
|
|
const pages = (page) => page.$$eval("#nav > button[data-view]", (bs) => bs.filter((b) => !b.hidden && !b.dataset.replaced && b.dataset.view !== "groups" && getComputedStyle(b).display !== "none" || b.classList.contains("tb-over")).map((b) => b.dataset.view));
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const [lang, moreWord] of Object.entries(LANGS)) {
|
|
for (const gateway of [false, true]) {
|
|
test(`${engine} ${lang}${gateway ? " gateway mode" : ""}: every page is reachable from the tab bar at 390px`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await open(browser, lang, gateway, gateway ? "providers" : "agents");
|
|
const all = await pages(page);
|
|
assert.ok(all.includes("library"), "the Library is a page here");
|
|
assert.equal(all.includes("agents"), !gateway, "Agents shows unless gateway mode leaves it out");
|
|
const bar = await tabs(page);
|
|
assert.equal(bar.length, 5, "five tabs: " + JSON.stringify(bar.map((b) => b.view)));
|
|
assert.equal(bar[4].view, "more", "the fifth is More");
|
|
assert.equal(bar[4].label, moreWord, "More in this language");
|
|
const vw = await page.evaluate(() => innerWidth), vh = await page.evaluate(() => innerHeight);
|
|
for (const b of bar) {
|
|
assert.ok(b.x >= 0 && b.x + b.w <= vw + 0.5, b.view + " is inside the window: " + JSON.stringify(b));
|
|
assert.ok(b.y + b.h <= vh + 0.5 && b.y > vh - 100, b.view + " sits at the window's foot: " + JSON.stringify(b));
|
|
assert.ok(b.h >= 44, b.view + " is a touch target");
|
|
}
|
|
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "nothing scrolls sideways");
|
|
const onBar = bar.slice(0, 4).map((b) => b.view);
|
|
// the bar's own pages open with a tap
|
|
for (const v of onBar) {
|
|
await page.locator(`#nav > button[data-view="${v}"]`).tap();
|
|
await page.waitForSelector("#view-" + v, { state: "visible" });
|
|
}
|
|
// the rest are in More's list, each with its icon, and open from it
|
|
const rest = all.filter((v) => !onBar.includes(v));
|
|
assert.ok(rest.length >= 1);
|
|
for (const v of rest) {
|
|
await page.locator("#nav .nav-more").tap();
|
|
const menu = page.locator(".nav-more-menu");
|
|
await menu.waitFor({ state: "visible" });
|
|
const items = await menu.locator(".pm-item").count();
|
|
assert.equal(items, rest.length, "More lists every page the bar hasn't");
|
|
assert.equal(await menu.locator(".pm-item .nav-ic").count(), rest.length, "each with its tab's icon");
|
|
const mb = await menu.boundingBox(), more = await page.locator("#nav .nav-more").boundingBox();
|
|
assert.ok(mb.y + mb.height <= more.y + 1, "the menu opens above the bar");
|
|
assert.ok(mb.x >= 0 && mb.x + mb.width <= vw + 0.5, "inside the window");
|
|
await menu.locator(".pm-item").nth(rest.indexOf(v)).tap();
|
|
await page.waitForSelector("#view-" + v, { state: "visible" });
|
|
assert.equal(await page.locator(".nav-more-menu").count(), 0, "the menu closes");
|
|
const now = await tabs(page);
|
|
assert.ok(now.find((b) => b.view === "more").on, "More is marked while " + v + " is open");
|
|
assert.ok(!now.slice(0, 4).some((b) => b.on), "no other tab is marked");
|
|
}
|
|
// back on a tab of the bar, More lets go of its mark
|
|
await page.locator(`#nav > button[data-view="${onBar[0]}"]`).tap();
|
|
await page.waitForSelector("#view-" + onBar[0], { state: "visible" });
|
|
assert.equal((await tabs(page)).find((b) => b.view === "more").on, false);
|
|
assert.deepEqual(page.errors, []);
|
|
});
|
|
}
|
|
}
|
|
|
|
test(`${engine}: the bar covers no part of a page or its status line`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await open(browser, "en", false, "settings");
|
|
const bar = await page.locator("#nav").boundingBox();
|
|
// the page's foot scrolls clear of the bar
|
|
const last = await page.evaluate(async () => {
|
|
const v = document.querySelector(".view:not([hidden])");
|
|
v.scrollTop = v.scrollHeight;
|
|
await new Promise((r) => setTimeout(r, 200));
|
|
return Math.min(v.getBoundingClientRect().bottom, Math.max(...[...v.children].filter((e) => e.getBoundingClientRect().height > 0).map((e) => e.getBoundingClientRect().bottom)));
|
|
});
|
|
assert.ok(last <= bar.y + 1, `the page's last line (${last}) ends above the bar (${bar.y})`);
|
|
// a status message sits above it
|
|
await page.evaluate(() => { const s = document.querySelector(".foot .status") || document.querySelector(".status"); s.textContent = "Saved"; });
|
|
await page.waitForTimeout(100);
|
|
const st = await page.evaluate(() => { const s = document.querySelector(".foot .status") || document.querySelector(".status"); const r = s.getBoundingClientRect(); return { y: r.y, h: r.height, shown: getComputedStyle(s).display !== "none" }; });
|
|
if (st.shown && st.h > 0) assert.ok(st.y + st.h <= bar.y + 1, "the status line is above the bar: " + JSON.stringify(st));
|
|
assert.deepEqual(page.errors, []);
|
|
});
|
|
|
|
test(`${engine}: a desktop browser keeps the header's tabs, with no More`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const context = await browser.newContext({ viewport: { width: 1280, height: 800 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
await page.route("**/*", serve("en", false));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
await page.waitForSelector("#view-providers", { state: "visible" });
|
|
await page.waitForTimeout(300);
|
|
assert.equal(await page.locator("#nav .nav-more").count(), 0);
|
|
assert.equal(await page.locator("#nav .tb-over").count(), 0);
|
|
const nav = await page.locator("#nav").boundingBox();
|
|
assert.ok(nav.y < 200, "the tabs are at the top: " + JSON.stringify(nav));
|
|
});
|
|
}
|