github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/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/setup-mirage'; 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 32 test('evaluations table is sortable', async function(assert) { 33 await Evaluations.sortBy('priority'); 34 35 assert.equal( 36 currentURL(), 37 `/jobs/${job.id}/evaluations?sort=priority`, 38 'the URL persists the sort parameter' 39 ); 40 const sortedEvaluations = evaluations.sortBy('priority').reverse(); 41 Evaluations.evaluations.forEach((evaluation, index) => { 42 const shortId = sortedEvaluations[index].id.split('-')[0]; 43 assert.equal( 44 evaluation.id, 45 shortId, 46 `Evaluation ${index} is ${shortId} with priority ${sortedEvaluations[index].priority}` 47 ); 48 }); 49 }); 50 51 test('when the job for the evaluations is not found, an error message is shown, but the URL persists', async function(assert) { 52 await Evaluations.visit({ id: 'not-a-real-job' }); 53 54 assert.equal( 55 server.pretender.handledRequests.findBy('status', 404).url, 56 '/v1/job/not-a-real-job', 57 'A request to the nonexistent job is made' 58 ); 59 assert.equal(currentURL(), '/jobs/not-a-real-job/evaluations', 'The URL persists'); 60 assert.ok(Evaluations.error.isPresent, 'Error message is shown'); 61 assert.equal(Evaluations.error.title, 'Not Found', 'Error message is for 404'); 62 }); 63 });