68 lines
2.4 KiB
JavaScript
68 lines
2.4 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
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);
|
|
});
|