github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/variable-paths-test.js (about)

     1  /* eslint-disable ember/avoid-leaking-state-in-ember-objects */
     2  import { module, test } from 'qunit';
     3  import { setupRenderingTest } from 'ember-qunit';
     4  import { render } from '@ember/test-helpers';
     5  import { hbs } from 'ember-cli-htmlbars';
     6  import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
     7  import pathTree from 'nomad-ui/utils/path-tree';
     8  import Service from '@ember/service';
     9  let tree;
    10  
    11  module('Integration | Component | variable-paths', function (hooks) {
    12    setupRenderingTest(hooks);
    13    hooks.beforeEach(function () {
    14      this.store = this.owner.lookup('service:store');
    15  
    16      const PATHSTRINGS = [
    17        { path: '/foo/bar/baz' },
    18        { path: '/foo/bar/bay' },
    19        { path: '/foo/bar/bax' },
    20        { path: '/a/b' },
    21        { path: '/a/b/c' },
    22        { path: '/a/b/canary' },
    23        { path: '/a/b/canine' },
    24        { path: '/a/b/chipmunk' },
    25        { path: '/a/b/c/d' },
    26        { path: '/a/b/c/dalmation/index' },
    27        { path: '/a/b/c/doberman/index' },
    28        { path: '/a/b/c/dachshund/index' },
    29        { path: '/a/b/c/dachshund/poppy' },
    30      ].map((x) => {
    31        const varInstance = this.store.createRecord('variable', x);
    32        varInstance.setAndTrimPath();
    33        return varInstance;
    34      });
    35      tree = new pathTree(PATHSTRINGS);
    36    });
    37  
    38    test('it renders without data', async function (assert) {
    39      assert.expect(2);
    40  
    41      this.set('emptyRoot', { children: {}, files: [] });
    42      await render(hbs`<VariablePaths @branch={{this.emptyRoot}} />`);
    43      assert.dom('tbody tr').exists({ count: 0 });
    44  
    45      await componentA11yAudit(this.element, assert);
    46    });
    47  
    48    test('it renders with data', async function (assert) {
    49      assert.expect(2);
    50  
    51      this.set('tree', tree);
    52      await render(hbs`<VariablePaths @branch={{this.tree.paths.root}} />`);
    53      assert.dom('tbody tr').exists({ count: 2 }, 'There are two rows');
    54  
    55      await componentA11yAudit(this.element, assert);
    56    });
    57  
    58    test('it allows for traversal: Folders', async function (assert) {
    59      assert.expect(3);
    60  
    61      this.set('tree', tree);
    62      await render(hbs`<VariablePaths @branch={{this.tree.paths.root}} />`);
    63      assert
    64        .dom('tbody tr:first-child td:first-child a')
    65        .hasAttribute(
    66          'href',
    67          '/ui/variables/path/foo/bar',
    68          'Correctly links a folder'
    69        );
    70      assert
    71        .dom('tbody tr:first-child svg')
    72        .hasAttribute(
    73          'data-test-icon',
    74          'folder',
    75          'Correctly renders the folder icon'
    76        );
    77  
    78      await componentA11yAudit(this.element, assert);
    79    });
    80  
    81    test('it allows for traversal: Files', async function (assert) {
    82      // Arrange Test Set-up
    83      const mockToken = Service.extend({
    84        selfTokenPolicies: [
    85          [
    86            {
    87              rulesJSON: {
    88                Namespaces: [
    89                  {
    90                    Name: '*',
    91                    Capabilities: ['list-jobs', 'alloc-exec', 'read-logs'],
    92                    Variables: {
    93                      Paths: [
    94                        {
    95                          Capabilities: ['list', 'read'],
    96                          PathSpec: '*',
    97                        },
    98                      ],
    99                    },
   100                  },
   101                ],
   102              },
   103            },
   104          ],
   105        ],
   106      });
   107  
   108      this.owner.register('service:token', mockToken);
   109  
   110      // End Test Set-up
   111  
   112      assert.expect(5);
   113  
   114      this.set('tree', tree.findPath('foo/bar'));
   115      await render(hbs`<VariablePaths @branch={{this.tree}} />`);
   116      assert
   117        .dom('tbody tr:first-child td:first-child a')
   118        .hasAttribute(
   119          'href',
   120          '/ui/variables/var/foo/bar/baz@default',
   121          'Correctly links the first file'
   122        );
   123      assert
   124        .dom('tbody tr:nth-child(2) td:first-child a')
   125        .hasAttribute(
   126          'href',
   127          '/ui/variables/var/foo/bar/bay@default',
   128          'Correctly links the second file'
   129        );
   130      assert
   131        .dom('tbody tr:nth-child(3) td:first-child a')
   132        .hasAttribute(
   133          'href',
   134          '/ui/variables/var/foo/bar/bax@default',
   135          'Correctly links the third file'
   136        );
   137      assert
   138        .dom('tbody tr:first-child svg')
   139        .hasAttribute(
   140          'data-test-icon',
   141          'file-text',
   142          'Correctly renders the file icon'
   143        );
   144      await componentA11yAudit(this.element, assert);
   145    });
   146  });