Files
NODEDC_DESIGN_GUIDELINE/scripts/navigation-cube.test.mjs
T
Codex cb534dbe39 feat(ui): add docking, viewport controls and composed settings
Add shared dock layouts, navigation cube, range bands, progress actions and comparison surfaces. Extend toolbar menus and loading composition, and align tokens, registry entries, documentation and the living catalog.
2026-10-29 09:38:25 +03:00

25 lines
1.5 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {cubeRegions} from '../packages/ui-react/dist/NavigationCube.js';
test('cube exposes exactly 26 unique face/edge/corner directions over all sides',()=>{
const views=[[0,0,0,1],[0,1,0,0],[0,Math.SQRT1_2,0,Math.SQRT1_2],[0,-Math.SQRT1_2,0,Math.SQRT1_2],[Math.SQRT1_2,0,0,Math.SQRT1_2],[-Math.SQRT1_2,0,0,Math.SQRT1_2]];
const dirs=new Set(views.flatMap(q=>cubeRegions(q).map(r=>r.direction.join(','))));
assert.equal(dirs.size,26);assert.ok(!dirs.has('0,0,0'));
assert.deepEqual(cubeRegions([0,0,0,1]).filter(r=>r.faceLabel).map(r=>r.faceLabel),['FRONT']);
assert.deepEqual(cubeRegions([Math.SQRT1_2,0,0,Math.SQRT1_2]).filter(r=>r.faceLabel).map(r=>r.faceLabel),['BOTTOM']);
for(const q of views)for(const r of cubeRegions(q)){assert.ok(!r.polygon.includes('NaN'));assert.ok(r.label);}
});
test('labels are projected in each face plane with no mirrored front-facing text',()=>{
const q=[.28,-.36,.12,.88],regions=cubeRegions(q).filter(r=>r.faceLabel);
assert.equal(regions.length,3);
for(const r of regions){
const [a,b,c,d,e,f]=r.textMatrix;assert.ok(a*d-b*c>0);assert.ok(a*d-b*c<1);
assert.ok(r.textMatrix.every(Number.isFinite));assert.ok(Math.abs(b)+Math.abs(c)>0.05);
const points=r.polygon.split(' ').map(p=>p.split(',').map(Number));
assert.ok(Math.abs(points.reduce((n,p)=>n+p[0],0)/4-e)<1e-9);
assert.ok(Math.abs(points.reduce((n,p)=>n+p[1],0)/4-f)<1e-9);
}
assert.deepEqual(cubeRegions([0,0,0,1]).find(r=>r.faceLabel).textMatrix.map(n=>n||0),[1,0,0,1,60,60]);
});