github.com/hernad/nomad@v1.6.112/ui/tests/acceptance/job-evaluations-test.js (about)

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