feat(org-chart): separate fixed and auto layout previews

This commit is contained in:
shkim4 committed 2026-10-12 18:02:39 +09:00
1 parent 80583eb4ca
commit a92913d6bc
18 files changed
+1211 -7

No files matched your search

@@ -0,0 +1,47 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { expandedPreviewRoots } from './expanded-layout.js';
import { createOrgChart } from './index.js';
import type { OrganizationTreeNode } from '../data/index.js';
const node = (id: string, parentId: string | null, type: 'root' | 'office' = 'office', children: OrganizationTreeNode[] = []): OrganizationTreeNode => ({
organization: { id, parentId, name: id, type, leaderId: null, displayOrder: 0 }, children,
});
test('initial preview keeps actual first-depth ancestry and defers descendants without mutating hierarchy', () => {
const grandchild = node('depth-2', 'depth-1');
const child = node('depth-1', 'root', 'office', [grandchild]);
const roots = [node('root', null, 'root', [child])];
const before = structuredClone(roots);
const projected = expandedPreviewRoots(roots);
assert.deepEqual(projected.map(item => item.organization.id), ['depth-1']);
assert.equal(projected[0]!.organization.parentId, 'root');
assert.deepEqual(projected[0]!.children, []);
assert.deepEqual(roots, before);
});
test('independent roots and normalized order stay independent in the initial preview', () => {
const roots = [node('first', null), node('root', null, 'root', [node('second', 'root'), node('third', 'root')])];
assert.deepEqual(expandedPreviewRoots(roots).map(item => item.organization.id), ['first', 'second', 'third']);
assert.deepEqual(expandedPreviewRoots([]), []);
});
const options = { dataSource: { load: async () => ({}) }, stylesheetUrls: { engine: '/engine.css', core: '/style.css' } };
test('layout defaults remain compatible and displayMode is an independent public option', () => {
for (const displayMode of ['interactive', 'readOnly'] as const) {
for (const layoutMode of [undefined, 'fixed', 'auto'] as const) {
const handle = createOrgChart({ ...options, displayMode, layoutMode });
assert.equal(handle.getState().status, 'idle');
handle.destroy();
}
}
});
test('invalid layout and unknown Auto company fail explicitly, while Fixed ignores company configuration', () => {
assert.throws(() => createOrgChart({ ...options, layoutMode: 'invalid' as 'auto' }), /layoutMode/);
assert.throws(() => createOrgChart({ ...options, layoutMode: 'auto', companyId: 'unknown' }), /companyId/);
const fixed = createOrgChart({ ...options, layoutMode: 'fixed', companyId: 'unknown' });
assert.equal(fixed.getState().status, 'idle');
fixed.destroy();
});