Files
magpie/internal/gui/tests/heatmap-scrollbar.test.cjs
T
yetone 47689f9fd9 gui: the usage heatmap scrolls under the app's thin thumb, not the system's bar (cybercaius on Discord)
cybercaius said the usage heatmap's scrollbar looked out of place beside
the rest of the window. .heat-scroll was the only scroller with
scrollbar-width: thin. In Chromium (so WebView2) a non-auto
scrollbar-width drops every ::-webkit-scrollbar rule and draws the
system's bar, gray track and all; on a Mac the WebView draws only the
overlay bar, which a mouse never shows. The line is gone, and the Mac
rules pages, dialogs and framed editors use take .heat-scroll too, so
the weeks scroll under the same 8px (Mac) or 10px thumb as the page.
No layout change.

heatmap-scrollbar.test.cjs: chromium and webkit, on and off a Mac, a
420px card of 53 weeks: the weeks overflow, scrollbar-width is auto,
and the heatmap's bar gutter equals a .view's.

What was run, at this commit's tree (base d2e0ea393):
- heatmap-scrollbar.test.cjs: red on the old app.css in all 4 cases
  ("expected 'auto', actual 'thin'"); dropping only scrollbar-width
  still fails the 2 Mac cases; 4/4 pass with the change.
- usage-heatmap.test.cjs (every language, 420 and 1100px, both
  engines): 26 pass, 0 fail.
- view-scrollbar, view-scrollbar-drag, sidebar-overlay-scrollbar,
  strip-scrollbar, ledger-hscroll, ledger-hscroll-foot, click-scroll and
  every usage-*.test.cjs: 3 reds, none from this change:
  usage-agents-hide (chromium and webkit, 10 subtests each) fails the
  same 22 of 22 on d2e0ea393's app.css (#3414, #2276);
  sidebar-overlay-scrollbar chromium fails one language per run
  ("dragged to the end: 193 of 222") on the old and new app.css alike,
  4 runs each way (#1863).
- Screenshots off and on a Mac, old and new: the system bar before, the
  page's thumb after.
- At the pushed head (this and the provider commit, rebased on
  origin/main 758be6d14): go test -tags nogui -count=1 ./internal/gui
  ./internal/provider in a sandbox HOME: ok (67.5s, 133.5s); gofmt -l
  clean; go vet ./internal/gui ./internal/provider ok; go build ./...
  (mac) ok; heatmap-scrollbar, usage-heatmap, view-scrollbar and
  view-wheel-unheard .test.cjs at 7ad6df865: 38 pass, 0 fail. Before the rebase, at
  30bd722ef on d2e0ea393: the same two packages ok (84.9s, 157.1s), and
  go vet ./... for mac, GOOS=linux -tags nogui and GOOS=windows ok, with
  linux nogui and windows go build ok.
  Not run: the full suite (the disk was full).
2026-10-25 19:40:37 +08:00

56 lines
3.0 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// cybercaius on Discord: the usage heatmap's scrollbar looked out of place
// beside the rest of the window. Its weeks scrolled under scrollbar-width:
// thin, which in Chromium (so WebView2) drops every ::-webkit-scrollbar rule
// and draws the system's bar, and on a Mac left the overlay bar a mouse never
// shows. The weeks now scroll under the same thin thumb as the page around
// them: the same gutter as a .view's, on a Mac and off one, in both engines.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const playwright = require("playwright");
const css = path.resolve(__dirname, "../assets/app.css");
const engines = process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"];
async function gutters(engine, mac) {
// headless Chromium hides scrollbars unless asked not to
const browser = await playwright[engine].launch(engine === "chromium" ? { ignoreDefaultArgs: ["--hide-scrollbars"] } : {});
try {
const page = await browser.newPage({ viewport: { width: 420, height: 400 } });
const cells = Array.from({ length: 53 * 7 }, () => "<i></i>").join("");
await page.setContent(`<style>${await fs.readFile(css, "utf8")}</style>
<body class="window${mac ? " mac" : ""}">
<div class="view" id="v" style="height:300px;overflow:auto;display:block"><div style="height:900px;width:2000px">
<div class="led-heat" style="width:360px"><div class="heat-scroll" id="h"><div class="heat-grid"><span></span>${cells}</div></div></div>
</div></div>
</body>`);
return await page.evaluate(() => {
const bar = (el, side) => {
const cs = getComputedStyle(el);
return side === "bottom"
? el.offsetHeight - el.clientHeight - parseFloat(cs.borderTopWidth) - parseFloat(cs.borderBottomWidth)
: el.offsetWidth - el.clientWidth - parseFloat(cs.borderLeftWidth) - parseFloat(cs.borderRightWidth);
};
const h = document.querySelector("#h");
const v = document.querySelector("#v");
return { scrolls: h.scrollWidth > h.clientWidth, width: getComputedStyle(h).scrollbarWidth, heat: bar(h, "bottom"), view: bar(v, "right") };
});
} finally {
await browser.close();
}
}
for (const engine of engines) {
for (const mac of [false, true]) {
test(`${engine}${mac ? ", on a Mac" : ", off a Mac"}: the heatmap's weeks scroll under the app's thin thumb, as the page does`, async () => {
const g = await gutters(engine, mac);
assert.ok(g.scrolls, "a narrow card's weeks overflow: " + JSON.stringify(g));
assert.equal(g.width, "auto", "no scrollbar-width, or Chromium draws the system's bar: " + JSON.stringify(g));
assert.ok(g.view > 0, "the page draws its thumb: " + JSON.stringify(g));
assert.equal(g.heat, g.view, "the heatmap's bar is the page's: " + JSON.stringify(g));
});
}
}