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); });