gui: the sidebar's open page moves from row to row on a spring, as iOS's selection does

The owner asked for the sidebar's pages (Providers, Routing, Gateway…)
to slide from one to the next like their sub-tabs do, "like iOS".

The open page's row is now marked by one shape (.nav-top-hl) that
navTopGo moves on a damped spring (NAV_SPRING: SwiftUI's response
0.42s, damping 0.84; navTopStep, four sub-steps a frame, dt capped):
- it sets off as the row is pressed, and comes back if the press
  leaves the row or the page refuses to be left;
- being physics, a press that changes its mind turns it with the speed
  it has, never a jump;
- it follows its row while Usage's tab list folds above it and lands
  where the row ends up;
- it is put in place, not sent, when the window opens on a kept page or
  the rows move under it at rest (ResizeObserver); away while Settings
  is open, it fades back in on its row; reduced motion jumps; the
  header's tabs keep their .thumb and draw none.
The rows give up their own ground (open, hovered, pressed) to it.
#nav is position: relative in the sidebar for it, so .seg's centring
left/top are reset (without that the whole list sat 105px right).

Tests:
- sidebar-glide.test.cjs (new): Chromium + WebKit, en + zh, 1024 and
  1440, plus 900 (header): at rest on its row and the list in the
  sidebar, no ground hovered, press sets off before release and comes
  back off the row, Providers→Usage→Agents by frames (≥3 moving
  frames, overshoot < 3px) landing on the row, Settings hides it and
  Routing brings it back, reduced motion jumps, no page errors.
  Broken by hand: without the left/top reset the list check goes red;
  before the "not seen yet" rule the boot slid from Agents (red).
- sidebar.test.cjs: a pressed page row no longer darkens itself (the
  shape comes to it); Settings still must.
- routing-idle-frame.test.cjs counted every self-asking rAF callback as
  Routing's loop, so navTopStep after the click read as 33 Routing
  frames. It now counts only callbacks no global holds (app.js's are
  globals; Routing's frame is in its plugin's scope). Broken by hand:
  Routing's loop made to always ask again → 4 red; green on main's
  assets and on this change.
- TestCoreScriptBudget: app.js 1,343,324 / core 1,535,084 with no room
  added; the sidebar is the window's shell, not a page a plugin can take.

Run:
- Full GUI suite at 183fa169b (this change on 3b10a403d), alone on the
  machine but at load ~216: 11942 pass, 104 fail. The 25 red files
  rerun at load ~10 on this change and on 3b10a403d: the same reds on
  both except routing-idle-frame (fixed above); plugin-card-update,
  segment-press-dialog and sidebar-overlay-scrollbar pass alone here
  (segment-press-dialog red alone on main: #3416). Reds on main, filed:
  #3402 #3403 #3404 #3405 #3406 #3407 #3408 #3409 #3410 #3411 #3412
  #3413 #3414 #3415; already filed: #3350 #3099 #3096 #3094 #3091
  #3104 #3001. codex-predictions and codex-auto-reset were red only at
  load ~216 and passed in both reruns.
- At the pushed head (rebased on f3eb92924): sidebar, sidebar-glide,
  nav-sub-unroll, side-toggle, side-width, header-relang,
  sidebar-tab-top, settings-tabs-stick, omarchy,
  sidebar-overlay-scrollbar, click-scroll, routing-idle-frame,
  plugin-card-update, segment-press-dialog, i18n-keys: 230/230;
  go test -tags nogui -run 'TestCoreScriptBudget|I18n|Docs'
  ./internal/gui: ok; gofmt -l clean.

Not tried: the real Linux app (WebKitGTK); this uses only rAF and
transforms, no view transition. Not run: the full Go suite (only
internal/gui's budget/docs tests; no Go code changed).
This commit is contained in:
yetone
2026-10-24 02:21:45 +08:00
parent a95f0b83ff
commit 17a2b00efb
8 changed files with 252 additions and 7 deletions
File diff suppressed because one or more lines are too long
+10 -1
View File
@@ -374,7 +374,7 @@ body.window:not(.mac):not(.linux):not(.web) .side-top { height: 10px; }
.side-bar > i { position: absolute; right: 2px; top: 0; width: 6px; min-height: 24px; border-radius: 3px; background: var(--muted); opacity: .55; transition: width .15s ease, opacity .15s ease; touch-action: none; }
.side-bar:hover > i, .side-bar.drag > i { width: 8px; opacity: .75; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { .side-bar, .side-bar > i { transition: none; } }
body.side-nav #nav { position: static; transform: none; display: flex; flex-direction: column; gap: 1px; padding: 0; border-radius: 0; }
body.side-nav #nav { position: relative; left: auto; top: auto; transform: none; display: flex; flex-direction: column; gap: 1px; padding: 0; border-radius: 0; }
body.side-nav .nav-gl { display: block; padding: 14px 8px 4px; font-size: 11px; font-weight: 500; letter-spacing: .04em; color: var(--muted); }
body.side-nav .nav-gl:first-child { padding-top: 2px; }
body.side-nav :is(#nav button[data-view], #prefs) {
@@ -385,6 +385,15 @@ body.side-nav :is(#nav button[data-view], #prefs) {
body.side-nav :is(#nav button[data-view], #prefs) > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
body.side-nav :is(#nav button[data-view], #prefs):hover:not(.on) { background: var(--pill); color: var(--fg); }
body.side-nav :is(#nav button[data-view], #prefs).on { background: var(--card); color: var(--fg); box-shadow: var(--seg-edge); font-weight: 500; }
/* the open page's row: one shape that moves from row to row on a spring
(app.js navTopGo), the rows' own ground given up to it. As with the
sub-rows', a row hovered or pressed has no ground of its own, which
would lie over the shape as it comes */
.nav-top-hl { display: none; }
body.side-nav #nav > .nav-top-hl:not([hidden]) { display: block; position: absolute; z-index: 0; top: 0; left: 0; right: 0; height: 30px; border-radius: 7px; background: var(--card); box-shadow: var(--seg-edge); pointer-events: none; will-change: transform; }
body.side-nav #side #nav.hl-on button[data-view]:is(.on, :hover, :active) { background: transparent; box-shadow: none; }
body.side-nav #nav.hl-on button[data-view] { transition: color .22s var(--ease); }
body.side-nav #nav.hl-on button[data-view] .nav-ic { transition: color .22s var(--ease); }
body.side-nav .nav-ic { display: block; flex: none; color: var(--muted); }
body.side-nav #prefs svg { flex: none; width: 15px; height: 15px; margin: 0 .5px; color: var(--muted); }
/* graphite, as a Mac sidebar is: no colour of its own, the page open in the
+91 -1
View File
@@ -24145,6 +24145,7 @@ async function show(v) {
if (on) b.setAttribute("aria-current", "page"); else b.removeAttribute("aria-current");
}
if (!sideNav()) { slide($("#nav"), "nav"); navInSight(); }
else navTopGo($("#nav").querySelector("button[data-view].on"), true);
}
$("#prefs").classList.toggle("on", v === "settings");
if (v === "settings") $("#prefs").setAttribute("aria-current", "page"); else $("#prefs").removeAttribute("aria-current");
@@ -24180,7 +24181,15 @@ function syncURL() {
const s = q.size ? "?" + q : location.pathname;
if (s !== location.search) history.replaceState(null, "", s);
}
if (mode === "window") for (const b of $("#nav").querySelectorAll("button[data-view]")) b.onclick = () => { show(b.dataset.view); b.blur(); };
if (mode === "window") for (const b of $("#nav").querySelectorAll("button[data-view]")) {
// beside the sidebar the selection goes as the finger comes down, as the
// sub-rows' does; let go off the row, or the page kept (a draft not
// given up), it goes back
b.onpointerdown = (e) => { if (e.button === 0) navTopGo(b, true); };
b.onpointercancel = () => navTopGo(navTopOn(), true);
b.onpointerleave = (e) => { if (e.buttons & 1) navTopGo(navTopOn(), true); };
b.onclick = () => { show(b.dataset.view).then((went) => { if (!went) navTopGo(navTopOn(), true); }); b.blur(); };
}
// setGatewayMode shows or leaves out gateway mode's pages' tabs; the page
// open, one of them, gives way to Providers
function setGatewayMode(on) {
@@ -24507,6 +24516,7 @@ function layoutNav() {
navSubs();
navSubs.quiet = false;
if (!on) { slide(nav, "nav"); navInSight(); } else { sideGwRead(); renderSideGw(); }
navTopGo(navTopOn(), false);
sideWidth();
renderSideToggle();
fitTop();
@@ -24786,6 +24796,86 @@ function navSubGlide(box, row) {
hl.style.transform = `translateY(${row.offsetTop}px)`;
hl.style.height = row.offsetHeight + "px";
}
// The open page's row beside the sidebar is marked by one shape too
// (.nav-top-hl), which moves to the row picked on a spring, as iOS moves a
// selection: quick off the mark, settling softly with the least overshoot.
// Being physics, not a timed curve, it is never thrown: a press that
// changes its mind turns it with the speed it has, and it follows its row
// while a list above folds away, landing where the row ends up rather
// than where it was when the press came.
var NAV_SPRING = { response: 0.42, damping: 0.84 }; // seconds, fraction: SwiftUI's terms
var navTop = { row: null, y: 0, h: 0, vy: 0, vh: 0, at: 0, raf: 0, seen: false };
const navTopOn = () => $("#nav")?.querySelector("button[data-view].on") || null;
function navTopHl() {
const nav = $("#nav");
let hl = nav.querySelector(":scope > .nav-top-hl");
if (!hl) {
hl = el("i", "nav-top-hl");
hl.hidden = true;
nav.append(hl);
// the rows moved at rest (the window, the language, a page left out):
// the shape stays on its row
new ResizeObserver(() => { if (!navTop.raf && navTop.row && !hl.hidden) navTopPut(hl, navTop.row); }).observe(nav);
}
return hl;
}
function navTopDraw(hl) {
hl.style.transform = `translateY(${navTop.y}px)`;
hl.style.height = navTop.h + "px";
}
function navTopPut(hl, row) {
Object.assign(navTop, { y: row.offsetTop, h: row.offsetHeight, vy: 0, vh: 0 });
navTopDraw(hl);
}
// navTopGo sends the shape to row, still unless glide
function navTopGo(row, glide) {
if (mode !== "window" || !$("#nav")) return;
const nav = $("#nav"), hl = navTopHl();
const to = sideNav() && row && !row.hidden && row.offsetParent ? row : null;
nav.classList.toggle("hl-on", !!to);
// the same row, the shape still: the rows moved under it, not a pick, so
// it stays on its row. And one not on screen yet (the window opening on
// the page it was left on) is put there, not sent
if (to && ((to === navTop.row && !navTop.raf) || !navTop.seen)) glide = false;
navTop.row = to;
if (!to) { cancelAnimationFrame(navTop.raf); navTop.raf = 0; hl.hidden = true; return; }
const appearing = hl.hidden;
hl.hidden = false;
if (!navTop.seen) requestAnimationFrame(() => requestAnimationFrame(() => { navTop.seen = !hl.hidden; }));
if (appearing || !glide || navCalm()) {
cancelAnimationFrame(navTop.raf);
navTop.raf = 0;
navTopPut(hl, to);
// back from Settings, whose row is at the foot: it comes up in place
if (appearing && glide && !navCalm()) hl.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 240, easing: NAV_EASE });
return;
}
if (!navTop.raf) { navTop.at = performance.now(); navTop.raf = requestAnimationFrame(navTopStep); }
}
function navTopStep(now) {
const nav = $("#nav"), hl = nav?.querySelector(":scope > .nav-top-hl"), row = navTop.row;
if (!hl || !row?.isConnected) { navTop.raf = 0; return; }
const dt = Math.min(1 / 30, Math.max(0, (now - navTop.at) / 1000));
navTop.at = now;
const k = (2 * Math.PI / NAV_SPRING.response) ** 2, c = 4 * Math.PI * NAV_SPRING.damping / NAV_SPRING.response;
const ty = row.offsetTop, th = row.offsetHeight;
// a few small steps a frame keep the spring true at any frame rate
for (let i = 0, d = dt / 4; i < 4; i++) {
navTop.vy += (k * (ty - navTop.y) - c * navTop.vy) * d;
navTop.y += navTop.vy * d;
navTop.vh += (k * (th - navTop.h) - c * navTop.vh) * d;
navTop.h += navTop.vh * d;
}
const still = Math.abs(ty - navTop.y) < 0.25 && Math.abs(navTop.vy) < 4 && Math.abs(th - navTop.h) < 0.25 && Math.abs(navTop.vh) < 4;
// at rest once there, and nothing above it still folding
if (still && !nav.querySelector(".nav-sub.moving, .nav-sub.leaving")) {
navTopPut(hl, row);
navTop.raf = 0;
return;
}
navTopDraw(hl);
navTop.raf = requestAnimationFrame(navTopStep);
}
function navSubEnter(box) {
if (navCalm()) return;
const cs = getComputedStyle(box);
+2
View File
@@ -67,4 +67,6 @@ html.omarchy .icon.winclose:hover { background: var(--red-soft); color: var(--re
html.omarchy ::selection { background: var(--om-sel); color: var(--accent); }
html.omarchy body.side-nav :is(#nav button[data-view], #prefs).on { background: var(--om-sel); box-shadow: inset 0 0 0 1px var(--om-sel-line); color: var(--accent); }
html.omarchy .nav-hl { background: var(--om-sel); }
html.omarchy body.side-nav #nav > .nav-top-hl { background: var(--om-sel); box-shadow: inset 0 0 0 1px var(--om-sel-line); }
html.omarchy body.side-nav #nav.hl-on button[data-view].on { background: transparent; box-shadow: none; }
html.omarchy .nav-s.cur { color: var(--accent); }
+2 -2
View File
@@ -15,8 +15,8 @@ import (
// so a page can't quietly grow back into the core; a change that needs more
// raises them and says why in its commit.
const (
appScriptBudget = 1_338_929 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23)
coreScriptBudget = 1_530_689 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added
appScriptBudget = 1_343_324 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23)
coreScriptBudget = 1_535_084 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added
)
func TestCoreScriptBudget(t *testing.T) {
@@ -98,7 +98,9 @@ const init = () => {
// the live dot's pulse, running or not
window.__pulses = () => [...document.querySelectorAll(".rt-livedot")].filter((d) => d.getAnimations().some((a) => a.playState === "running")).length;
window.requestAnimationFrame = (cb) => {
const self = typeof cb === "function" && /requestAnimationFrame\s*\(\s*([A-Za-z_$][\w$]*)/.test(cb.toString()) && new RegExp(`\\b${RegExp.$1}\\s*\\(`).test(cb.toString());
// a loop of the core's (app.js's sidebar spring, navTopStep) is a
// global; the Routing plugin's is in its own scope
const self = typeof cb === "function" && window[cb.name] !== cb && /requestAnimationFrame\s*\(\s*([A-Za-z_$][\w$]*)/.test(cb.toString()) && new RegExp(`\\b${RegExp.$1}\\s*\\(`).test(cb.toString());
if (typeof cb === "function" && (cb.name === "frame" || self)) window.__seenFrame = true;
return raf((ts) => { if (cb.name === "step") window.__steps++; if (typeof cb === "function" && (cb.name === "frame" || self)) window.__frames++; cb(ts); });
};
+140
View File
@@ -0,0 +1,140 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Beside the sidebar the open page's row is marked by one shape (app.js
// navTopGo) that moves to the row picked on a spring, as iOS moves a
// selection, the way the sub-rows' selection slides: it sets off as the row
// is pressed, goes back when the press is let go off the row, follows its
// row while the list of the page left folds away above it, and lands on
// it. The rows have no ground of their own under it, hovered or not.
// Settings, at the foot, has its own; the shape is away while it is open.
// With reduced motion it is put there at once. In the header's tabs it
// isn't drawn. Both engines, two languages, two widths.
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(lang) {
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: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" } });
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { url: "http://127.0.0.1:3425", running: true, window: true }, plugins: [] });
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
if (url.pathname.startsWith("/api/")) return json({});
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
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: "" }); }
};
}
// the shape's top and height, and a row's, in the sidebar's list
const shape = (page) => page.evaluate(() => {
const hl = document.querySelector("#nav > .nav-top-hl");
if (!hl || hl.hidden || getComputedStyle(hl).display === "none") return null;
const b = hl.getBoundingClientRect();
return { top: b.top, h: b.height };
});
const rowOf = (page, v) => page.evaluate((v) => {
const b = document.querySelector(`#nav button[data-view="${v}"]`).getBoundingClientRect();
return { top: b.top, h: b.height };
}, v);
// the shape's tops, one a frame, until it has been still for 20 frames
const watch = (page) => page.evaluate(() => { window.__tops = []; const f = () => { const hl = document.querySelector("#nav > .nav-top-hl"); window.__tops.push(hl.getBoundingClientRect().top); const t = window.__tops; if (t.length < 400 && !(t.length > 20 && t.slice(-20).every((y) => y === t[t.length - 1]))) requestAnimationFrame(f); else window.__still = true; }; window.__still = false; requestAnimationFrame(f); });
const settled = async (page) => { await page.waitForFunction(() => window.__still); return page.evaluate(() => window.__tops); };
const on = async (page, v) => {
const [s, r] = [await shape(page), await rowOf(page, v)];
assert(s, `the shape is drawn for ${v}`);
assert(Math.abs(s.top - r.top) < 0.5 && Math.abs(s.h - r.h) < 0.5, `the shape on ${v}'s row: ${JSON.stringify(s)} vs ${JSON.stringify(r)}`);
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: the sidebar's open page is one shape that springs from row to row`, 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 width of [1024, 1440]) await t.test(`${lang} ${width}`, async () => {
const context = await browser.newContext({ viewport: { width, height: 800 } });
const page = await context.newPage();
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang));
await page.goto("http://magpie.test/?view=providers");
await page.waitForSelector("#nav > .nav-top-hl:not([hidden])");
assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "a sidebar at " + width);
await on(page, "providers");
// the list where it was before the shape: in the sidebar, at its edge
const [side, nav, hl] = await page.evaluate(() => ["#side", "#nav", "#nav > .nav-top-hl"].map((q) => { const b = document.querySelector(q).getBoundingClientRect(); return { l: b.left, r: b.right }; }));
assert(nav.l - side.l < 16 && nav.r <= side.r && hl.l === nav.l && hl.r === nav.r, `the list in the sidebar: ${JSON.stringify({ side, nav, hl })}`);
const ground = (v) => page.locator(`#nav button[data-view="${v}"]`).evaluate((b) => getComputedStyle(b).backgroundColor);
assert.equal(await ground("providers"), "rgba(0, 0, 0, 0)", "the open row's ground is the shape's");
// hovered, a row has no ground of its own
await page.locator('#nav button[data-view="agents"]').hover();
assert.equal(await ground("agents"), "rgba(0, 0, 0, 0)", "no block under the pointer ahead of the shape");
// pressed, the shape sets off before the press ends; let go off the
// row, it goes back and the page stays
const usage = await page.locator('#nav button[data-view="usage"]').boundingBox();
await page.mouse.move(usage.x + 20, usage.y + usage.height / 2);
await watch(page);
await page.mouse.down();
await page.waitForFunction((from) => Math.abs(document.querySelector("#nav > .nav-top-hl").getBoundingClientRect().top - from) > 2, (await shape(page)).top);
assert.equal(await page.locator("#nav button.on").getAttribute("data-view"), "providers", "the page changes only on the click");
await page.mouse.move(usage.x + usage.width + 300, usage.y + 200);
await page.mouse.up();
await settled(page);
assert.equal(await page.locator("#nav button.on").getAttribute("data-view"), "providers");
await on(page, "providers");
// to Usage, then up to Agents while Usage's tabs fold away under it:
// it moves by frames, never at once, and lands on its row
for (const v of ["usage", "agents"]) {
const from = (await shape(page)).top, to = (await rowOf(page, v)).top;
await watch(page);
await page.locator(`#nav button[data-view="${v}"]`).click();
const tops = await settled(page);
await on(page, v);
const moving = tops.filter((y) => Math.abs(y - from) > 0.5 && Math.abs(y - (tops[tops.length - 1])) > 0.5);
assert(moving.length >= 3, `${v}: the shape moves by frames, not at once: ${tops.map(Math.round).join(" ")}`);
const end = tops[tops.length - 1], past = Math.max(...tops.map((y) => Math.sign(end - from) * (y - end)));
assert(past < 3, `${v}: it settles with at most a little overshoot (${past.toFixed(2)}px): ${tops.map(Math.round).join(" ")}`);
if (v === "usage") assert(Math.abs(end - to) < 0.5);
}
// Settings has its own; back, the shape is on the row picked
await page.locator("#prefs").click();
await page.waitForFunction(() => document.querySelector("#nav > .nav-top-hl").hidden);
assert.notEqual(await page.locator("#prefs").evaluate((b) => getComputedStyle(b).backgroundColor), "rgba(0, 0, 0, 0)", "Settings keeps its own selection");
await page.locator('#nav button[data-view="routing"]').click();
await page.waitForTimeout(300);
await on(page, "routing");
// reduced motion: there at once
await page.emulateMedia({ reducedMotion: "reduce" });
await page.locator('#nav button[data-view="gateway"]').click();
await on(page, "gateway");
assert.deepEqual(errors, []);
await context.close();
});
await t.test("the header's tabs draw none", async () => {
const context = await browser.newContext({ viewport: { width: 900, height: 700 } });
const page = await context.newPage();
page.setDefaultTimeout(5000);
await page.route("**/*", serve("en"));
await page.goto("http://magpie.test/?view=providers");
await page.waitForSelector("#nav button.on");
assert.ok(!(await page.evaluate(() => document.body.classList.contains("side-nav"))));
await page.locator('#nav button[data-view="usage"]').click();
assert.equal(await shape(page), null);
assert.notEqual(await page.locator("#nav > .thumb").count(), 0, "the header's own thumb");
await context.close();
});
});
}
+3 -1
View File
@@ -84,7 +84,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.mouse.move(box.x + box.width + 400, box.y);
await page.mouse.up();
assert.equal(tf, "none", `${sel} pressed is not squeezed`);
assert.notEqual(pressed, bg, `${sel} pressed darkens`);
// a page's row has the open page's shape come to it instead
// (sidebar-glide.test.cjs); Settings, at the foot, darkens
if (sel === "#prefs") assert.notEqual(pressed, bg, `${sel} pressed darkens`);
}
// the gateway's address at the foot, read once the window has settled