github.com/anuvu/nomad@v0.8.7-atom1/ui/tests/integration/job-page/parts/placement-failures-test.js (about)

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