fix: align org chart hierarchy and typography weights
This commit is contained in:
1 parent
72d427fcd2
commit
d42466f5eb
33 files changed
+358
-85
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fixture from '../../../../examples/org-chart/data-expanded-large.json';
|
||||
import small from '../../../../examples/org-chart/data-expanded-small.json';
|
||||
import medium from '../../../../examples/org-chart/data-expanded-medium.json';
|
||||
import { companyColorPresets, type CompanyId } from '../company-color-presets.js';
|
||||
import {
|
||||
calculateSummary, createOrgChartExampleDataset, JsonOrgChartDataSource,
|
||||
@@ -20,17 +22,34 @@ function assertContract(dataset: OrgChartDataset) {
|
||||
assert.equal(new Set(dataset.affiliations.map(affiliation => affiliation.id)).size, dataset.affiliations.length);
|
||||
const summary = calculateSummary(dataset).raw;
|
||||
assert.equal(summary.total, dataset.employees.length, 'leaders count once as employees');
|
||||
const pending = normalizeOrgChartDataset(dataset).roots.map(node => ({ node, depth: 1 }));
|
||||
const pending = normalizeOrgChartDataset(dataset).roots.map(node => ({ node, depth: 1, underCell: false }));
|
||||
let maximumDepth = 0;
|
||||
while (pending.length) {
|
||||
const { node, depth } = pending.pop()!;
|
||||
const { node, depth, underCell } = pending.pop()!;
|
||||
assert.ok(!(underCell && node.organization.type === 'team'), `team ${node.organization.id} must not descend from a cell`);
|
||||
maximumDepth = Math.max(maximumDepth, depth);
|
||||
pending.push(...node.children.map(child => ({ node: child, depth: depth + 1 })));
|
||||
pending.push(...node.children.map(child => ({ node: child, depth: depth + 1, underCell: underCell || node.organization.type === 'cell' })));
|
||||
}
|
||||
assert.ok(maximumDepth >= 3);
|
||||
assert.ok(new Set(Object.values(summary.byOrganization).map(value => value.direct)).size > 1, 'unequal organization membership');
|
||||
}
|
||||
|
||||
test('generated small/medium/large fixtures follow the hierarchy, retaining team -> cell examples', () => {
|
||||
for (const dataset of [small, medium, fixture] as OrgChartDataset[]) assertContract(dataset);
|
||||
const byId = new Map(base.organizations.map(org => [org.id, org]));
|
||||
const cells = base.organizations.filter(org => org.type === 'cell');
|
||||
assert.equal(cells.length, companies.length * 2);
|
||||
for (const cell of cells) assert.equal(byId.get(cell.parentId!)!.type, 'team');
|
||||
});
|
||||
|
||||
test('hierarchy regression check rejects a team below an indirect cell ancestor', () => {
|
||||
const invalid = structuredClone(base);
|
||||
const office = invalid.organizations.find(org => org.id === 'hanmac-office-sibling')!;
|
||||
office.parentId = 'hanmac-cell-0';
|
||||
invalid.organizations.find(org => org.id === 'hanmac-team-sibling')!.parentId = office.id;
|
||||
assert.throws(() => assertContract(invalid), /must not descend from a cell/);
|
||||
});
|
||||
|
||||
for (const employeeCount of sizes) {
|
||||
test(`total ${employeeCount} contains exactly that many unique employees across all seven preset companies`, () => {
|
||||
const dataset = createOrgChartExampleDataset(base, { scope: 'total', employeeCount });
|
||||
|
||||
Reference in new issue
Block a user