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

     1  import hbs from 'htmlbars-inline-precompile';
     2  import { findAll, find, render } from '@ember/test-helpers';
     3  import { module, test } from 'qunit';
     4  import { setupRenderingTest } from 'ember-qunit';
     5  import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
     6  import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
     7  import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
     8  
     9  module('Integration | Component | job-page/parts/placement-failures', function(hooks) {
    10    setupRenderingTest(hooks);
    11  
    12    hooks.beforeEach(function() {
    13      fragmentSerializerInitializer(this.owner);
    14      window.localStorage.clear();
    15      this.store = this.owner.lookup('service:store');
    16      this.server = startMirage();
    17      this.server.create('namespace');
    18    });
    19  
    20    hooks.afterEach(function() {
    21      this.server.shutdown();
    22      window.localStorage.clear();
    23    });
    24  
    25    test('when the job has placement failures, they are called out', async function(assert) {
    26      this.server.create('job', { failedPlacements: true, createAllocations: false });
    27      await this.store.findAll('job');
    28  
    29      const job = this.store.peekAll('job').get('firstObject');
    30      await job.reload();
    31  
    32      this.set('job', job);
    33  
    34      await render(hbs`
    35        <JobPage::Parts::PlacementFailures @job={{job}} />)
    36      `);
    37  
    38      const failedEvaluation = this.get('job.evaluations')
    39        .filterBy('hasPlacementFailures')
    40        .sortBy('modifyIndex')
    41        .reverse()
    42        .get('firstObject');
    43      const failedTGAllocs = failedEvaluation.get('failedTGAllocs');
    44  
    45      assert.ok(find('[data-test-placement-failures]'), 'Placement failures section found');
    46  
    47      const taskGroupLabels = findAll('[data-test-placement-failure-task-group]').map(title =>
    48        title.textContent.trim()
    49      );
    50  
    51      failedTGAllocs.forEach(alloc => {
    52        const name = alloc.get('name');
    53        assert.ok(
    54          taskGroupLabels.find(label => label.includes(name)),
    55          `${name} included in placement failures list`
    56        );
    57        assert.ok(
    58          taskGroupLabels.find(label => label.includes(alloc.get('coalescedFailures') + 1)),
    59          'The number of unplaced allocs = CoalescedFailures + 1'
    60        );
    61      });
    62  
    63      await componentA11yAudit(this.element, assert);
    64    });
    65  
    66    test('when the job has no placement failures, the placement failures section is gone', async function(assert) {
    67      this.server.create('job', { noFailedPlacements: true, createAllocations: false });
    68      await this.store.findAll('job');
    69  
    70      const job = this.store.peekAll('job').get('firstObject');
    71      await job.reload();
    72  
    73      this.set('job', job);
    74  
    75      await render(hbs`
    76        <JobPage::Parts::PlacementFailures @job={{job}} />)
    77      `);
    78  
    79      assert.notOk(find('[data-test-placement-failures]'), 'Placement failures section not found');
    80    });
    81  });