Files
client/test/tree-layout.test.mjs
T
omar e6464bc4ed feat: checkpoint account-free client workflows and source-matched UI
Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring.

Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
2026-11-01 19:43:18 +03:00

111 lines
4.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { collapsedFor, toggleCollapsed } from '../app/renderer/js/tree-collapse.js';
import { clampSplit, createSplitter } from '../app/renderer/js/splitter.js';
test('collapse is server-scoped, toggles independently and prunes missing channels', () => {
const first = toggleCollapsed([], 'one:9987', 7, [7, 8]);
assert.deepEqual([...collapsedFor(first, 'one:9987')], [7]);
assert.equal(collapsedFor(first, 'two:9987').size, 0);
const next = toggleCollapsed(first, 'one:9987', 8, [8]);
assert.deepEqual([...collapsedFor(next, 'one:9987')], [8]);
assert.deepEqual(toggleCollapsed(next, 'one:9987', 8, [8]), []);
assert.deepEqual(first, [{ server: 'one:9987', channels: [7] }]);
});
test('collapsed preference retention is bounded', () => {
let entries = [];
for (let i = 0; i < 40; i++) entries = toggleCollapsed(entries, `server-${i}`, 1, [1]);
assert.equal(entries.length, 32);
assert.equal(entries[0].server, 'server-8');
const channels = Array.from({ length: 513 }, (_, i) => i + 1);
const large = toggleCollapsed([{ server: 'one', channels: channels.slice(0, 512) }], 'one', 513, channels);
assert.equal(large[0].channels.length, 512);
assert.equal(large[0].channels.at(-1), 513);
});
class Target extends EventTarget {
attrs = new Map();
capture = null;
setAttribute(name, value) { this.attrs.set(name, value); }
focus() {}
setPointerCapture(id) { this.capture = id; }
hasPointerCapture(id) { return this.capture === id; }
releasePointerCapture() { this.capture = null; }
}
const dispatch = (target, type, values = {}) => {
const event = new Event(type, { cancelable: true });
Object.assign(event, values);
target.dispatchEvent(event);
return event;
};
for (const axis of ['x', 'y']) {
test(`${axis} splitter captures drag, clamps, cancels, uses keyboard and cleans up`, () => {
const handle = new Target();
const win = new Target();
const classes = new Set();
const body = { dataset: {}, classList: { add: (v) => classes.add(v), remove: (v) => classes.delete(v) } };
handle.ownerDocument = { defaultView: win, body };
let value = 300;
let desired = 300;
let max = 700;
const commits = [];
const splitter = createSplitter({ handle, axis, getValue: () => desired, getBounds: () => ({ min: 200, max }),
onChange: (v) => { value = v; }, onCommit: (v) => { desired = v; commits.push(v); }, getDefault: () => 320 });
const coord = axis === 'x' ? 'clientX' : 'clientY';
dispatch(handle, 'pointerdown', { button: 0, pointerId: 1, [coord]: 100 });
dispatch(handle, 'pointermove', { pointerId: 1, [coord]: 900 });
assert.equal(value, 700);
assert.equal(handle.capture, 1);
dispatch(handle, 'pointerup', { pointerId: 1 });
assert.deepEqual(commits, [700]);
assert.equal(classes.size, 0);
assert.equal(body.dataset.resizeAxis, undefined);
dispatch(handle, 'keydown', { key: 'Home' });
assert.equal(value, 200);
dispatch(handle, 'keydown', { key: axis === 'x' ? 'ArrowRight' : 'ArrowDown' });
assert.equal(value, 216);
dispatch(handle, 'keydown', { key: 'Enter' });
assert.equal(value, 320);
dispatch(handle, 'pointerdown', { button: 0, pointerId: 2, [coord]: 100 });
dispatch(handle, 'pointermove', { pointerId: 2, [coord]: 200 });
assert.equal(value, 420);
dispatch(handle, 'pointercancel', { pointerId: 2 });
assert.equal(value, 320);
max = 250;
dispatch(win, 'resize');
assert.equal(value, 250);
assert.equal(desired, 320);
max = 700;
splitter.refresh();
assert.equal(value, 320);
splitter.destroy();
dispatch(handle, 'keydown', { key: 'End' });
assert.equal(value, 320);
});
}
test('split values reject nonfinite numbers and stay inside bounds', () => {
assert.equal(clampSplit(NaN, { min: 200, max: 500 }), 200);
assert.equal(clampSplit(-1, { min: 200, max: 500 }), 200);
assert.equal(clampSplit(600, { min: 200, max: 500 }), 500);
});
test('explicit reset is distinct from a user-sized value equal to the default', () => {
const handle = new Target();
handle.ownerDocument = { defaultView: new Target(), body: { dataset: {}, classList: { add() {}, remove() {} } } };
const commits = [];
const resets = [];
const splitter = createSplitter({ handle, axis: 'x', getValue: () => 304, getBounds: () => ({ min: 200, max: 700 }),
onChange() {}, onCommit: (v) => commits.push(v), onReset: (v) => resets.push(v), getDefault: () => 320 });
dispatch(handle, 'keydown', { key: 'ArrowRight' });
assert.deepEqual(commits, [320]);
assert.deepEqual(resets, []);
dispatch(handle, 'keydown', { key: 'Enter' });
dispatch(handle, 'dblclick');
assert.deepEqual(resets, [320, 320]);
assert.deepEqual(commits, [320]);
splitter.destroy();
});