import { describe, it } from 'node:test'; import type { NavigationNode, NavigationStateNode } from './navigation.ts'; /** Accepts any value except `null` or `undefined` */ // deno-lint-ignore ban-types const definedValues = (..._args: {}[]) => { /* empty */ }; const nav: NavigationStateNode[] = []; const navTree: NavigationNode[] = []; describe('Navigation', () => { describe('Navigation', () => { it('should contain expendable and selected', () => { nav.forEach(n => { const { expandable, selected } = n; definedValues(expandable, selected); }); }); it('should contain `link` property', () => { nav.forEach(n => { if (n.type === 'PAGE_LINK') { definedValues(n.link); } }); }); it('should NOT contain `link` property', () => { nav.forEach(n => { if (n.type !== 'PAGE_LINK') { // @ts-expect-error this property should not exist n.link; } }); }); it('should be able to use e.g. find/map on children arrays', () => { nav.forEach(n => { n.children.find(n2 => definedValues(n2, true)); n.children.map(n2 => n2); }); }); it('should recursively use the union of all values for type', () => { nav.forEach(n => { if (n.type === 'PAGE_LINK') { n.children.forEach(n2 => { if (n2.type === 'PRODUCT') { definedValues(n2); } }); } }); }); }); describe('NavigationTree', () => { it('should NOT contain expendable and selected', () => { navTree.forEach(n => { // @ts-expect-error this property should not exist n.expendable; // @ts-expect-error this property should not exist n.selected; }); }); it('should contain `link` property', () => { navTree.forEach(n => { if (n.type === 'PAGE_LINK') { definedValues(n.link); } }); }); it('should NOT contain `link` property', () => { navTree.forEach(n => { if (n.type !== 'PAGE_LINK') { // @ts-expect-error this property should not exist n.link; } }); }); it('should be able to use e.g. find/map on children arrays', () => { navTree.forEach(n => { n.children.find(n2 => definedValues(n2, true)); n.children.map(n2 => n2); }); }); it('should recursively use the union of all values for type', () => { navTree.forEach(n => { if (n.type === 'PAGE_LINK') { n.children.forEach(n2 => { if (n2.type === 'PRODUCT') { definedValues(n2); } }); } }); }); }); });