gui: sidebar-tab-top also holds the page's own strip and page switching still, in every language (#1844)
lainbo's test checked the sidebar rows in English and Chinese. The rule the
change sits beside ("where the reader is", 73af4c28) is that a tab clicked
in the page's own strip leaves the page where it is, and switching pages
keeps each where it was left. The test now checks both, so a later change
that lets the new scroll reach them goes red:
- the sidebar part runs in en, zh, zh-TW, ja and de, and after the tab
switches goes to Settings and back to the Library: each is where it was
left;
- a new test per engine, with the sidebar turned off (1100px, navLayout
top) and in a window narrower than SIDE_AT (900px), scrolls Library ›
MCP servers to its foot and clicks Skills in the page's strip: the page
is not taken to its top. Every language.
Run: sidebar-tab-top 34/34 (Chromium, WebKit) with the change. The strip
test passes 22/22 on main's app.js too (unchanged behaviour). Broken by
hand: the strip's segs click scrolling its view to 0 fails the strip test
10/10; Settings' place reset to 0 on a page switch fails "Settings is where
it was left"; the row scrolling with the tab already open fails "the tab
already open leaves the page where it is"; scrollOnPurpose() without the
click's event fails "Allowances opens at its top" (refused, 177/228).
This commit is contained in:
@@ -190,8 +190,11 @@ the room kept at the foot going as the reader scrolls back; and the wheel.
|
||||
`sidebar-tab-top.test.cjs` checks that a tab picked in the sidebar opens at
|
||||
its top: Settings › General scrolled to its foot and Allowances picked,
|
||||
Library › MCP servers scrolled to its foot and Skills picked, and back. The
|
||||
tab already open, picked again, leaves the page where it is. Chromium and
|
||||
WebKit, English and Chinese.
|
||||
tab already open, picked again, leaves the page where it is, and another
|
||||
page and back finds each where it was left. The page's own strip (the
|
||||
sidebar turned off, and a window narrower than `SIDE_AT`) is unchanged: a
|
||||
tab clicked there leaves the Library where it was. Chromium and WebKit, in
|
||||
every language.
|
||||
|
||||
`routing-days-fit.test.cjs` checks Routing › Requests' day bar with the 30
|
||||
days the gateway keeps (#961): at 1100px, 733px (1100 at 150% text size) and
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
// tabs share its one scroll: scrolled to the foot of Settings › General and
|
||||
// Allowances picked, or of Library › MCP servers and Skills picked, the new
|
||||
// tab was shown from where the old one had been left, at its foot. The tab
|
||||
// already open, picked again, leaves the page where it is. Chromium and
|
||||
// WebKit, English and Chinese; no backend, the API is faked here.
|
||||
// already open, picked again, leaves the page where it is, and another page
|
||||
// and back finds each where it was left. The page's own strip is unchanged.
|
||||
// Chromium and WebKit, every language; no backend, the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
@@ -64,6 +65,9 @@ const room = (page, v) => page.locator(v).evaluate((e) => e.scrollHeight - e.cli
|
||||
const words = {
|
||||
en: { allowances: "Allowances", mcp: "MCP servers", skills: "Skills" },
|
||||
zh: { allowances: "额度", mcp: "MCP 服务器", skills: "技能" },
|
||||
"zh-TW": { allowances: "額度", mcp: "MCP 伺服器", skills: "技能" },
|
||||
ja: { allowances: "利用枠", mcp: "MCP サーバー", skills: "スキル" },
|
||||
de: { allowances: "Kontingente", mcp: "MCP-Server", skills: "Skills" },
|
||||
};
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
@@ -120,6 +124,50 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await settle(page);
|
||||
assert.equal(await top(page, libv), 0, "MCP servers opens at its top");
|
||||
|
||||
// another page and back: each page is where it was left, as before
|
||||
const libAt = await toFoot(page, libv);
|
||||
await page.locator("#prefs").click();
|
||||
await settle(page);
|
||||
const setAt = await top(page, set);
|
||||
assert.ok(setAt > 100, `Settings is where it was left: ${setAt}`);
|
||||
await page.locator('#nav button[data-view="library"]').click();
|
||||
await settle(page);
|
||||
assert.equal(await top(page, libv), libAt, "the Library is where it was left");
|
||||
|
||||
assert.deepEqual(errors, []);
|
||||
await context.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// The page's own strip (the header's tabs: the sidebar turned off, or a window
|
||||
// narrower than SIDE_AT) is unchanged: a tab clicked there, like every click,
|
||||
// leaves the page where it is (73af4c28, "where the reader is").
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(`${engine}: a tab picked in the page's own strip leaves the page where it is`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const [name, width, layout] of [["sidebar off", 1100, "top"], ["narrow", 900, ""]]) for (const lang of Object.keys(words)) await t.test(`${name}, ${lang}`, async () => {
|
||||
const context = await browser.newContext({ viewport: { width, height: 480 }, reducedMotion: "reduce" });
|
||||
await context.addInitScript((layout) => { try { localStorage.setItem("magpie.settingsTab", "general"); localStorage.setItem("magpie.libTab", "mcp"); if (layout) localStorage.setItem("magpie.navLayout", layout); } catch {} }, layout);
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang));
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.waitForSelector("#nav button.on");
|
||||
assert.ok(!(await page.evaluate(() => document.body.classList.contains("side-nav"))), "no sidebar");
|
||||
|
||||
const libv = "#view-library";
|
||||
await page.locator('#nav button[data-view="library"]').click();
|
||||
await page.locator(`${libv} .lib-row, ${libv} .row`).first().waitFor();
|
||||
const at = await toFoot(page, libv);
|
||||
await page.locator(`${libv} .lib-tabs > button`).nth(1).click();
|
||||
await page.waitForFunction(() => document.querySelectorAll("#view-library .lib-tabs > button")[1]?.classList.contains("on"));
|
||||
await settle(page);
|
||||
const after = await top(page, libv);
|
||||
assert.ok(after > 100, `the strip's click left the Library where it was, not at its top: ${at} then ${after}`);
|
||||
assert.deepEqual(errors, []);
|
||||
await context.close();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user