github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/integration/components/job-page/parts/body-test.js (about)

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