Files
monkey-ai-web/test/unit/sidebar-scroll.test.js
T
zhanjunhao 8a48765a46 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

49 lines
1.6 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { revealActiveSidebarItem } from '../../src/helpers/sidebarScroll.js';
function container(top, bottom, visible = true) {
return {
scrollHeight: 1200,
clientHeight: 500,
clientTop: 2,
scrollTop: 100,
getBoundingClientRect: () => ({ top: 100 }),
querySelector: () => ({
getClientRects: () => (visible ? [{}] : []),
getBoundingClientRect: () => ({ top, bottom }),
}),
};
}
test('reveals an item below the sidebar viewport with the minimum scroll', () => {
const node = container(650, 692);
revealActiveSidebarItem(node);
assert.equal(node.scrollTop, 190);
});
test('reveals an item above the sidebar viewport with the minimum scroll', () => {
const node = container(50, 92);
revealActiveSidebarItem(node);
assert.equal(node.scrollTop, 48);
});
test('preserves manual scrolling when the selected menu is already fully visible', () => {
const node = container(120, 162);
revealActiveSidebarItem(node);
assert.equal(node.scrollTop, 100);
});
test('does not force open a hidden group or scroll a menu without overflow', () => {
const hidden = container(650, 692, false);
revealActiveSidebarItem(hidden);
assert.equal(hidden.scrollTop, 100);
const short = container(650, 692);
short.scrollHeight = 500;
revealActiveSidebarItem(short);
assert.equal(short.scrollTop, 100);
revealActiveSidebarItem(null);
});
test('handles pending or unavailable active items without changing scroll', () => {
const node = container(650, 692);
node.querySelector = () => null;
revealActiveSidebarItem(node);
assert.equal(node.scrollTop, 100);
});