github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/acceptance/job-evaluations-test.js (about)

     1  import { currentURL } from '@ember/test-helpers';
     2  import { module, test } from 'qunit';
     3  import { setupApplicationTest } from 'ember-qunit';
     4  import { setupMirage } from 'ember-cli-mirage/test-support';
     5  import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
     6  import Evaluations from 'nomad-ui/tests/pages/jobs/job/evaluations';
     7  
     8  let job;
     9  let evaluations;
    10  
    11  module('Acceptance | job evaluations', function(hooks) {
    12    setupApplicationTest(hooks);
    13    setupMirage(hooks);
    14  
    15    hooks.beforeEach(async function() {
    16      job = server.create('job', { noFailedPlacements: true, createAllocations: false });
    17      evaluations = server.db.evaluations.where({ jobId: job.id });
    18  
    19      await Evaluations.visit({ id: job.id });
    20    });
    21  
    22    test('it passes an accessibility audit', async function(assert) {
    23      await a11yAudit(assert);
    24    });
    25  
    26    test('lists all evaluations for the job', async function(assert) {
    27      assert.equal(Evaluations.evaluations.length, evaluations.length, 'All evaluations are listed');
    28  
    29      const sortedEvaluations = evaluations.sortBy('modifyIndex').reverse();
    30  
    31      Evaluations.evaluations.forEach((evaluation, index) => {
    32        const shortId = sortedEvaluations[index].id.split('-')[0];
    33        assert.equal(evaluation.id, shortId, `Evaluation ${index} is ${shortId}`);
    34      });
    35  
    36      assert.equal(document.title, `Job ${job.name} evaluations - Nomad`);
    37    });
    38  
    39    test('evaluations table is sortable', async function(assert) {
    40      await Evaluations.sortBy('priority');
    41  
    42      assert.equal(
    43        currentURL(),
    44        `/jobs/${job.id}/evaluations?sort=priority`,
    45        'the URL persists the sort parameter'
    46      );
    47      const sortedEvaluations = evaluations.sortBy('priority').reverse();
    48      Evaluations.evaluations.forEach((evaluation, index) => {
    49        const shortId = sortedEvaluations[index].id.split('-')[0];
    50        assert.equal(
    51          evaluation.id,
    52          shortId,
    53          `Evaluation ${index} is ${shortId} with priority ${sortedEvaluations[index].priority}`
    54        );
    55      });
    56    });
    57  
    58    test('when the job for the evaluations is not found, an error message is shown, but the URL persists', async function(assert) {
    59      await Evaluations.visit({ id: 'not-a-real-job' });
    60  
    61      assert.equal(
    62        server.pretender.handledRequests
    63          .filter(request => !request.url.includes('policy'))
    64          .findBy('status', 404).url,
    65        '/v1/job/not-a-real-job',
    66        'A request to the nonexistent job is made'
    67      );
    68      assert.equal(currentURL(), '/jobs/not-a-real-job/evaluations', 'The URL persists');
    69      assert.ok(Evaluations.error.isPresent, 'Error message is shown');
    70      assert.equal(Evaluations.error.title, 'Not Found', 'Error message is for 404');
    71    });
    72  });