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.
178 lines
11 KiB
JavaScript
178 lines
11 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A routing group made from a model is added (悠悠哥 on Discord: in a small
|
|
// window, the new group "Hy4 preview" of its one model, Hy4 preview from
|
|
// WorkBuddy, did nothing on Add). A group opened from a model — by the
|
|
// picker's or the provider editor's "Make a routing group of it", or the
|
|
// tray panel's ?newgroup= — had no fast members in its draft, so Add threw
|
|
// and posted nothing; and a hidden classifier left an empty cell in the
|
|
// editor's grid, so Levels' label sat at the right and its choices under
|
|
// the labels. Now each label is beside its field, Add posts the group, and
|
|
// what goes wrong is said where it is seen:
|
|
// a save the server refuses shows its error in the window, in sight, the
|
|
// editor stays, and Add takes another press (it stayed busy, deaf to
|
|
// clicks). In Chromium and WebKit, English and Chinese, in a
|
|
// small window and a large one.
|
|
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");
|
|
// the rows a group's editor folds under Advanced, opened
|
|
const openAdvanced = async (page) => {
|
|
const d = page.locator(".rt-gedit .rt-gadv");
|
|
await d.waitFor({ state: "attached" });
|
|
if (!(await d.evaluate((e) => e.open))) await d.locator(":scope > summary").click();
|
|
};
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const MODEL = "workbuddy/hy4-preview";
|
|
|
|
function serve(lang, posts, refuse) {
|
|
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
|
const groups = { groups: [], pools: [], deciders: [], models: [{ id: MODEL, name: "Hy4 preview", provider: "workbuddy", providerName: "WorkBuddy", icon: "generic" }] };
|
|
return async (r) => {
|
|
const req = r.request(), url = new URL(req.url());
|
|
const json = (data, status = 200) => r.fulfill({ status, json: data });
|
|
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
|
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (req.method() === "POST" && url.pathname.startsWith("/api/")) posts.push({ path: url.pathname, body: JSON.parse(req.postData() || "{}") });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
if (url.searchParams.get("wait")) return new Promise(() => {});
|
|
return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
|
}
|
|
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
|
if (url.pathname === "/api/groups/save" && refuse) return r.fulfill({ status: 400, contentType: "text/plain", body: "group hy4-preview: no such model" });
|
|
if (url.pathname === "/api/groups" || url.pathname.startsWith("/api/groups/")) return json(groups);
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999", groups: [] } });
|
|
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 words = { en: { add: "Add", addModel: "Add another model" }, zh: { add: "添加", addModel: "再加一个模型" } };
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of ["en", "zh"]) {
|
|
for (const [width, height] of [[600, 420], [1000, 700]]) {
|
|
test(`${engine} ${lang} ${width}x${height}: a routing group made from a model is added`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const open = async (posts, refuse) => {
|
|
const page = await (await browser.newContext({ viewport: { width, height }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000); // the page's first load, slow on a busy machine
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, posts, refuse));
|
|
await page.goto(`http://magpie.test/?view=groups&newgroup=${encodeURIComponent(MODEL)}`);
|
|
const ed = page.locator("#view-groups:not([hidden]) .rt-gedit");
|
|
await ed.waitFor();
|
|
await ed.locator("input").first().fill("Hy4 preview");
|
|
// the reader wheels down until Add itself is under the pointer's
|
|
// reach, and it has settled, as the page moves for no one else
|
|
const add = ed.getByRole("button", { name: words[lang].add, exact: true });
|
|
const seen = () => add.evaluate((btn) => {
|
|
const r = btn.getBoundingClientRect(), x = r.left + r.width / 2, y = r.top + r.height / 2;
|
|
return document.elementFromPoint(x, y)?.closest("button") === btn ? { x, y } : null;
|
|
});
|
|
await page.mouse.move(width / 2, height / 2);
|
|
let at = null;
|
|
for (let i = 0; i < 60; i++) {
|
|
const now = await seen();
|
|
if (now && at && Math.abs(now.y - at.y) < 0.5) break;
|
|
at = now;
|
|
if (!now) await page.mouse.wheel(0, 120);
|
|
await page.waitForTimeout(80);
|
|
}
|
|
assert.ok(at, "the wheel reaches Add, and nothing covers it");
|
|
// Add is clicked where it is, and what is under it is checked: the
|
|
// error it answers with comes in at the foot of the page and, in a
|
|
// one column editor (under 760px), covers Add itself until the view
|
|
// is scrolled to its end. The reader wheels down to the end of the
|
|
// page here, so that the press lands whatever the error does.
|
|
const clickAdd = async () => {
|
|
for (let i = 0; i < 80; i++) {
|
|
const done = await page.evaluate(() => {
|
|
const v = document.querySelector("#view-groups");
|
|
return v.scrollTop + v.clientHeight >= v.scrollHeight - 1;
|
|
});
|
|
if (done) break;
|
|
await page.mouse.wheel(0, 120);
|
|
await page.waitForTimeout(60);
|
|
}
|
|
// and back up until the whole of Add is in the view: a press on
|
|
// its middle, with its top still under the header, can land on
|
|
// the header in WebKit
|
|
const whole = () => add.evaluate((btn) => {
|
|
const r = btn.getBoundingClientRect(), v = btn.closest("main.view").getBoundingClientRect();
|
|
return r.top >= v.top && r.bottom <= v.bottom;
|
|
});
|
|
let now = (await whole()) && (await seen());
|
|
for (let i = 0; i < 80 && !now; i++) {
|
|
await page.mouse.wheel(0, -60);
|
|
await page.waitForTimeout(60);
|
|
now = (await whole()) && (await seen());
|
|
}
|
|
assert.ok(now, "Add is under the pointer's reach to be clicked");
|
|
await page.mouse.click(now.x, now.y);
|
|
};
|
|
return { page, ed, errors, clickAdd };
|
|
};
|
|
|
|
// Add posts the group of its one model
|
|
let posts = [];
|
|
let { page, ed, errors, clickAdd } = await open(posts, false);
|
|
// every label beside its own field, or over it where the editor is one
|
|
// column: a hidden classifier left its cell behind, and Levels' label
|
|
// sat at the right, its choices below. Under 760px the editor is one
|
|
// column on purpose (plugins/routing/routing.css), so the label is above its field
|
|
// there — beside is only what a wide window can ask for.
|
|
const oneColumn = width <= 760;
|
|
await openAdvanced(page); // Levels and the rest folded under it, measured too
|
|
const rows = await ed.evaluate((e, oneColumn) => [...e.children, ...(e.querySelector(":scope > .rt-gadv > .inner")?.children || [])].filter((c) => c.matches("label") && !c.hidden && c.offsetParent).map((l) => {
|
|
const f = l.nextElementSibling, a = l.getBoundingClientRect(), b = f.getBoundingClientRect();
|
|
const beside = a.right <= b.left + 1 && Math.abs(a.top - b.top) < 12;
|
|
const above = a.bottom <= b.top + 1 && a.left <= b.left + 1;
|
|
return { label: l.textContent, beside, above };
|
|
}), oneColumn);
|
|
assert.ok(rows.length >= 6, JSON.stringify(rows));
|
|
assert.deepEqual(rows.filter((r) => !(oneColumn ? r.above : r.beside)), [],
|
|
oneColumn ? "each label over its field, the editor in one column" : "each label beside its field");
|
|
await clickAdd();
|
|
for (let i = 0; i < 40 && !posts.some((p) => p.path === "/api/groups/save"); i++) await page.waitForTimeout(50);
|
|
const saved = posts.find((p) => p.path === "/api/groups/save")?.body;
|
|
assert.deepEqual(saved?.members, [MODEL], "the group is posted with its model");
|
|
assert.deepEqual(saved.fast, [], "no member sent fast");
|
|
assert.equal(saved.name, "Hy4 preview");
|
|
assert.deepEqual(errors, [], "nothing throws");
|
|
await page.context().close();
|
|
|
|
// refused, the error is said in sight and the editor stays
|
|
posts = [];
|
|
({ page, ed, errors, clickAdd } = await open(posts, true));
|
|
await clickAdd();
|
|
const st = page.locator("#status.err");
|
|
await st.waitFor();
|
|
assert.match(await st.textContent(), /no such model/);
|
|
const box = await st.boundingBox();
|
|
assert.ok(box && box.width > 0 && box.y >= 0 && box.y + box.height <= height + 1, `the error is in sight: ${JSON.stringify(box)}`);
|
|
assert.equal(await ed.isVisible(), true, "the editor stays open");
|
|
// and Add takes a second press, where it stayed busy and took none
|
|
const saves = () => posts.filter((p) => p.path === "/api/groups/save").length;
|
|
assert.equal(saves(), 1);
|
|
for (let i = 0; i < 40 && await ed.locator(".bar .primary.busy").count(); i++) await page.waitForTimeout(50);
|
|
await clickAdd();
|
|
for (let i = 0; i < 40 && saves() < 2; i++) await page.waitForTimeout(50);
|
|
assert.equal(saves(), 2, "a second Add is posted");
|
|
assert.deepEqual(errors, [], "nothing throws");
|
|
});
|
|
}
|
|
}
|
|
}
|