github.com/hernad/nomad@v1.6.112/ui/tests/unit/utils/compact-path-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import compactPath from 'nomad-ui/utils/compact-path'; 7 import pathTree from 'nomad-ui/utils/path-tree'; 8 import { module, test } from 'qunit'; 9 10 const PATHSTRINGS = [ 11 { path: 'a/b/c/d/e/foo0' }, 12 { path: 'a/b/c/d/e/bar1' }, 13 { path: 'a/b/c/d/e/baz2' }, 14 { path: 'a/b/c/d/e/z/z/z/z/z/z/z/z/z/z/foo3' }, 15 { path: 'z/y/x/dalmation/index' }, 16 { path: 'z/y/x/doberman/index' }, 17 { path: 'z/y/x/dachshund/index' }, 18 { path: 'z/y/x/dachshund/poppy' }, 19 ]; 20 21 module('Unit | Utility | compact-path', function () { 22 test('it compacts empty folders correctly', function (assert) { 23 const tree = new pathTree(PATHSTRINGS); 24 assert.ok( 25 'a' in tree.paths.root.children, 26 'root.a exists in the path tree despite having no files and only a single path' 27 ); 28 assert.equal( 29 compactPath(tree.root.children['a'], 'a').name, 30 'a/b/c/d/e', 31 'but root.a is displayed compacted down to /e from its root level folder' 32 ); 33 assert.equal( 34 compactPath(tree.findPath('z/y'), 'y').name, 35 'y/x', 36 'Path z/y is compacted to y/x, since it has a single child' 37 ); 38 assert.equal( 39 compactPath(tree.findPath('z/y/x'), 'x').name, 40 'x', 41 'Path z/y/x is uncompacted, since it has multiple children' 42 ); 43 assert.equal( 44 compactPath(tree.findPath('a/b/c/d/e/z'), 'z').name, 45 'z/z/z/z/z/z/z/z/z/z', 46 'Long path is recursively compacted' 47 ); 48 }); 49 });