github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/tests/integration/job-page/parts/body-test.js (about)

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