github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/tests/integration/job-page/parts/body-test.js (about)

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