github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/job-page/parts/body-test.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { module, test } from 'qunit';
     7  import { setupRenderingTest } from 'ember-qunit';
     8  import { find, findAll, render } from '@ember/test-helpers';
     9  import hbs from 'htmlbars-inline-precompile';
    10  import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
    11  import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
    12  
    13  module('Integration | Component | job-page/parts/body', function (hooks) {
    14    setupRenderingTest(hooks);
    15  
    16    hooks.beforeEach(function () {
    17      window.localStorage.clear();
    18      this.server = startMirage();
    19      this.server.createList('namespace', 3);
    20    });
    21  
    22    hooks.afterEach(function () {
    23      this.server.shutdown();
    24      window.localStorage.clear();
    25    });
    26  
    27    test('includes a subnav for the job', async function (assert) {
    28      this.set('job', {});
    29  
    30      await render(hbs`
    31        <JobPage::Parts::Body @job={{job}}>
    32          <div class="inner-content">Inner content</div>
    33        </JobPage::Parts::Body>
    34      `);
    35      assert.ok(find('[data-test-subnav="job"]'), 'Job subnav is rendered');
    36    });
    37  
    38    test('the subnav includes the deployments link when the job is a service', async function (assert) {
    39      assert.expect(4);
    40  
    41      const store = this.owner.lookup('service:store');
    42      const job = await store.createRecord('job', {
    43        id: '["service-job","default"]',
    44        type: 'service',
    45      });
    46  
    47      this.set('job', job);
    48  
    49      await render(hbs`
    50        <JobPage::Parts::Body @job={{job}}>
    51          <div class="inner-content">Inner content</div>
    52        </JobPage::Parts::Body>
    53      `);
    54  
    55      const subnavLabels = findAll('[data-test-tab]').map((anchor) =>
    56        anchor.textContent.trim()
    57      );
    58      assert.ok(
    59        subnavLabels.some((label) => label === 'Definition'),
    60        'Definition link'
    61      );
    62      assert.ok(
    63        subnavLabels.some((label) => label === 'Versions'),
    64        'Versions link'
    65      );
    66  
    67      assert.ok(
    68        subnavLabels.some((label) => label === 'Deployments'),
    69        'Deployments link'
    70      );
    71  
    72      await componentA11yAudit(this.element, assert);
    73    });
    74  
    75    test('the subnav does not include the deployments link when the job is not a service', async function (assert) {
    76      const store = this.owner.lookup('service:store');
    77      const job = await store.createRecord('job', {
    78        id: '["batch-job","default"]',
    79        type: 'batch',
    80      });
    81  
    82      this.set('job', job);
    83  
    84      await render(hbs`
    85        <JobPage::Parts::Body @job={{job}}>
    86          <div class="inner-content">Inner content</div>
    87        </JobPage::Parts::Body>
    88      `);
    89  
    90      const subnavLabels = findAll('[data-test-tab]').map((anchor) =>
    91        anchor.textContent.trim()
    92      );
    93      assert.ok(
    94        subnavLabels.some((label) => label === 'Definition'),
    95        'Definition link'
    96      );
    97      assert.ok(
    98        subnavLabels.some((label) => label === 'Versions'),
    99        'Versions link'
   100      );
   101      assert.notOk(
   102        subnavLabels.some((label) => label === 'Deployments'),
   103        'Deployments link'
   104      );
   105    });
   106  
   107    test('body yields content to a section after the subnav', async function (assert) {
   108      this.set('job', {});
   109  
   110      await render(hbs`
   111        <JobPage::Parts::Body @job={{job}}>
   112          <div class="inner-content">Inner content</div>
   113        </JobPage::Parts::Body>
   114      `);
   115  
   116      assert.ok(
   117        find('[data-test-subnav="job"] + .section > .inner-content'),
   118        'Content is rendered immediately after the subnav'
   119      );
   120    });
   121  });