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