github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/unit/utils/compact-path-test.js (about)

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