github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/job-page/parts/placement-failures-test.js (about)

     1  /* eslint-disable qunit/require-expect */
     2  /* Mirage fixtures are random so we can't expect a set number of assertions */
     3  import hbs from 'htmlbars-inline-precompile';
     4  import { findAll, find, render } from '@ember/test-helpers';
     5  import { module, test } from 'qunit';
     6  import { setupRenderingTest } 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  import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
    10  
    11  module(
    12    'Integration | Component | job-page/parts/placement-failures',
    13    function (hooks) {
    14      setupRenderingTest(hooks);
    15  
    16      hooks.beforeEach(function () {
    17        fragmentSerializerInitializer(this.owner);
    18        window.localStorage.clear();
    19        this.store = this.owner.lookup('service:store');
    20        this.server = startMirage();
    21        this.server.create('namespace');
    22      });
    23  
    24      hooks.afterEach(function () {
    25        this.server.shutdown();
    26        window.localStorage.clear();
    27      });
    28  
    29      test('when the job has placement failures, they are called out', async function (assert) {
    30        this.server.create('job', {
    31          failedPlacements: true,
    32          createAllocations: false,
    33        });
    34        await this.store.findAll('job');
    35  
    36        const job = this.store.peekAll('job').get('firstObject');
    37        await job.reload();
    38  
    39        this.set('job', job);
    40  
    41        await render(hbs`
    42        <JobPage::Parts::PlacementFailures @job={{job}} />)
    43      `);
    44  
    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(
    53          find('[data-test-placement-failures]'),
    54          'Placement failures section found'
    55        );
    56  
    57        const taskGroupLabels = findAll(
    58          '[data-test-placement-failure-task-group]'
    59        ).map((title) => title.textContent.trim());
    60  
    61        failedTGAllocs.forEach((alloc) => {
    62          const name = alloc.get('name');
    63          assert.ok(
    64            taskGroupLabels.find((label) => label.includes(name)),
    65            `${name} included in placement failures list`
    66          );
    67          assert.ok(
    68            taskGroupLabels.find((label) =>
    69              label.includes(alloc.get('coalescedFailures') + 1)
    70            ),
    71            'The number of unplaced allocs = CoalescedFailures + 1'
    72          );
    73        });
    74  
    75        await componentA11yAudit(this.element, assert);
    76      });
    77  
    78      test('when the job has no placement failures, the placement failures section is gone', async function (assert) {
    79        this.server.create('job', {
    80          noFailedPlacements: true,
    81          createAllocations: false,
    82        });
    83        await this.store.findAll('job');
    84  
    85        const job = this.store.peekAll('job').get('firstObject');
    86        await job.reload();
    87  
    88        this.set('job', job);
    89  
    90        await render(hbs`
    91        <JobPage::Parts::PlacementFailures @job={{job}} />)
    92      `);
    93  
    94        assert.notOk(
    95          find('[data-test-placement-failures]'),
    96          'Placement failures section not found'
    97        );
    98      });
    99    }
   100  );