Files
magpie/internal/gui/tests/strip-scrollbar.test.cjs
T
yetone 0f6defe78b gui: on a Mac a region or agent strip scrolls with no bar, so a click right after a scroll picks the option under it (#1620)
tencent-cloud.test.cjs was red in WebKit now and then: a region clicked
was not picked. The cause, found by scrolling the strip from the test and
clicking 30ms later: on a Mac page (body.mac) WebKit shows its overlay
scrollbar over the lower half of a scrolled strip for a moment, and
elementsFromPoint at an option's centre returned the strip, not the
option. A press there goes to the bar's track, which pages the strip
sideways (smoothly, 198 -> 44) and picks nothing. A reader on a Mac who
scrolls the regions and clicks at once meets the same miss.

On a Mac these strips (.segs.regions, Connect's segs, #sessAgent) now
scroll with no bar, as a Mac's own tab strips do (scrollbar-width: none,
::-webkit-scrollbar display none). Other systems keep their thin bar.
z-index, isolation and position on the options didn't help; only hiding
the bar did.

Tests:
- tencent-cloud.test.cjs: new "a region clicked right after the strip
  scrolled is the one picked", 480x1200 (the strip in the window; it
  checks so), 10 rounds over 5 scroll positions. Without the CSS WebKit
  missed 39 of 50 clicks (40 of 50 on origin/main 5dfcf4346); with it 0.
- strip-scrollbar.test.cjs now says the Mac strip has no bar (width none,
  bar 0), and goes red without the CSS.

Run: tencent-cloud 20/20 green in WebKit and 20/20 in Chromium;
strip-scrollbar, sess-agent-strip, usage-sessions-agents-fit,
tencent-access-key, system-one, click-scroll, segs-press-redraw in both
engines (segs-press-redraw's Chromium 440px case is red now and then
under load in other trees too: it is one of the Settings tests #1659 is
moving onto the page's last settings read; green 8/8 in each engine
with this change).
2026-10-12 01:55:05 +08:00

45 lines
2.3 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// ARNO on Discord: the Sessions page's agent tabs had grown a thick Windows
// scrollbar, arrows and all, under them. The strip (and a provider's region
// picker, which shares its class) set scrollbar-width, and in Chromium — so
// WebView2 — that drops every ::-webkit-scrollbar rule, the app's thin thumb
// with them. Off a Mac the strip now scrolls under a 6px thumb. On a Mac it
// scrolls with no bar: the system's overlay bar showed over the options for a
// moment after a scroll and took their clicks (#1620, tencent-cloud's
// "clicked right after the strip scrolled" clicks it in WebKit).
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium } = require("playwright");
const css = path.resolve(__dirname, "../assets/app.css");
async function gutter(mac) {
// headless Chromium hides scrollbars unless asked not to
const browser = await chromium.launch({ ignoreDefaultArgs: ["--hide-scrollbars"] });
try {
const page = await browser.newPage({ viewport: { width: 400, height: 300 } });
const tabs = Array.from({ length: 12 }, (_, i) => `<button class="opt">Agent ${i}</button>`).join("");
await page.setContent(`<style>${await fs.readFile(css, "utf8")}</style>
<body class="window${mac ? " mac" : ""}"><div class="segs regions sm-agents" id="s">${tabs}</div></body>`);
return await page.$eval("#s", (s) => ({ scrolls: s.scrollWidth > s.clientWidth, bar: s.offsetHeight - s.clientHeight - parseFloat(getComputedStyle(s).borderTopWidth) - parseFloat(getComputedStyle(s).borderBottomWidth), width: getComputedStyle(s).scrollbarWidth }));
} finally {
await browser.close();
}
}
test("off a Mac the overflowing strip scrolls under the app's 6px thumb, not the classic bar", async () => {
const g = await gutter(false);
assert.ok(g.scrolls, "the strip overflows");
assert.equal(g.width, "auto");
assert.equal(g.bar, 6);
});
test("on a Mac the strip scrolls with no bar over its options", async () => {
const g = await gutter(true);
assert.ok(g.scrolls, "the strip overflows");
assert.equal(g.width, "none");
assert.equal(g.bar, 0);
});