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