Files
Netcatty/components/settings/settingsFocus.test.ts
T
bincxz fcd122d4a1 fix: stabilize AI session handoff, system manager tabs, and settings scroll
Prevent StrictMode draft demotion after send, keep workspace AI maintenance
mounted with a workspaces list, and keep live Streamdown markdown while
streaming. System Manager gains overflow-aware icon-only tabs, customize
layout, GPU vendor badges, and cache-preserving overview remounts. Settings
search scrolls only the content pane so traffic lights stay put.
2026-08-10 16:59:39 +08:00

73 lines
2.1 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
test("settings search focus scrolls the content pane, not the window viewport", () => {
const source = readFileSync(new URL("./settingsFocus.ts", import.meta.url), "utf8");
const uiSource = readFileSync(new URL("./settings-ui.tsx", import.meta.url), "utf8");
assert.match(source, /scrollSettingsAnchorIntoView/);
assert.match(source, /findSettingsScrollContainer/);
assert.match(source, /data-settings-scroll-pane/);
assert.match(source, /preventScroll:\s*true/);
// Viewport centering lifts the whole settings window under macOS traffic lights.
assert.doesNotMatch(source, /block:\s*["']center["']/);
assert.match(uiSource, /data-settings-scroll-pane/);
});
test("scrollSettingsAnchorIntoView prefers marked pane over document scroll", async () => {
const { scrollSettingsAnchorIntoView } = await import("./settingsFocus.ts");
const calls: Array<{ top: number; behavior?: ScrollBehavior }> = [];
const scroller = {
scrollHeight: 2000,
clientHeight: 400,
scrollTop: 0,
getBoundingClientRect: () => ({
top: 100,
left: 0,
bottom: 500,
right: 400,
width: 400,
height: 400,
x: 0,
y: 100,
toJSON() {
return this;
},
}),
scrollTo(opts: { top: number; behavior?: ScrollBehavior }) {
calls.push(opts);
this.scrollTop = opts.top;
},
} as unknown as HTMLElement;
const anchor = {
getBoundingClientRect: () => ({
top: 700,
left: 0,
bottom: 760,
right: 200,
width: 200,
height: 60,
x: 0,
y: 700,
toJSON() {
return this;
},
}),
closest(selector: string) {
if (selector === "[data-settings-scroll-pane]") return scroller;
return null;
},
parentElement: scroller,
} as unknown as HTMLElement;
scrollSettingsAnchorIntoView(anchor, "auto");
assert.equal(calls.length, 1);
// elTopInScroller = 700 - 100 + 0 = 600; minus 24 padding → 576
assert.equal(calls[0].top, 576);
assert.equal(calls[0].behavior, "auto");
});