UNPKG

@apptus/esales-api

Version:

Library for making requests to Elevate 4 API v3

104 lines (88 loc) 2.58 kB
import { describe, it } from '#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[] = []; const suite = describe('Navigation'); const navSuite = describe(suite, 'Navigation'); const navTreeSuite = describe(suite, 'NavigationTree'); it(navSuite, 'should contain expendable and selected', () => { nav.forEach(n => { const { expandable, selected } = n; definedValues(expandable, selected); }); }); it(navSuite, 'should contain `link` property', () => { nav.forEach(n => { if (n.type === 'PAGE_LINK') { definedValues(n.link); } }); }); it(navSuite, 'should NOT contain `link` property', () => { nav.forEach(n => { if (n.type !== 'PAGE_LINK') { // @ts-expect-error this property should not exist n.link; } }); }); it(navSuite, '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(navSuite, '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); } }); } }); }); it(navTreeSuite, '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(navTreeSuite, 'should contain `link` property', () => { navTree.forEach(n => { if (n.type === 'PAGE_LINK') { definedValues(n.link); } }); }); it(navTreeSuite, 'should NOT contain `link` property', () => { navTree.forEach(n => { if (n.type !== 'PAGE_LINK') { // @ts-expect-error this property should not exist n.link; } }); }); it(navTreeSuite, '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(navTreeSuite, '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); } }); } }); });