2019-03-13 00:08:16 +00:00
|
|
|
import { currentURL } from '@ember/test-helpers';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2019-09-26 18:47:07 +00:00
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2020-07-28 17:59:14 +00:00
|
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
2018-07-11 16:37:58 +00:00
|
|
|
import Evaluations from 'nomad-ui/tests/pages/jobs/job/evaluations';
|
2018-07-07 00:07:53 +00:00
|
|
|
|
|
|
|
let job;
|
|
|
|
let evaluations;
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Acceptance | job evaluations', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
hooks.beforeEach(async function() {
|
2018-07-07 00:07:53 +00:00
|
|
|
job = server.create('job', { noFailedPlacements: true, createAllocations: false });
|
|
|
|
evaluations = server.db.evaluations.where({ jobId: job.id });
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Evaluations.visit({ id: job.id });
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2018-07-07 00:07:53 +00:00
|
|
|
|
2020-07-28 17:59:14 +00:00
|
|
|
test('it passes an accessibility audit', async function(assert) {
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('lists all evaluations for the job', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.equal(Evaluations.evaluations.length, evaluations.length, 'All evaluations are listed');
|
2018-07-11 16:37:58 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const sortedEvaluations = evaluations.sortBy('modifyIndex').reverse();
|
2018-07-11 16:37:58 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
Evaluations.evaluations.forEach((evaluation, index) => {
|
|
|
|
const shortId = sortedEvaluations[index].id.split('-')[0];
|
|
|
|
assert.equal(evaluation.id, shortId, `Evaluation ${index} is ${shortId}`);
|
|
|
|
});
|
2019-07-17 20:02:58 +00:00
|
|
|
|
|
|
|
assert.equal(document.title, `Job ${job.name} evaluations - Nomad`);
|
2018-07-11 16:37:58 +00:00
|
|
|
});
|
2018-07-07 00:07:53 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('evaluations table is sortable', async function(assert) {
|
|
|
|
await Evaluations.sortBy('priority');
|
2018-07-07 00:07:53 +00:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/jobs/${job.id}/evaluations?sort=priority`,
|
|
|
|
'the URL persists the sort parameter'
|
|
|
|
);
|
2018-07-11 16:37:58 +00:00
|
|
|
const sortedEvaluations = evaluations.sortBy('priority').reverse();
|
|
|
|
Evaluations.evaluations.forEach((evaluation, index) => {
|
|
|
|
const shortId = sortedEvaluations[index].id.split('-')[0];
|
|
|
|
assert.equal(
|
|
|
|
evaluation.id,
|
|
|
|
shortId,
|
|
|
|
`Evaluation ${index} is ${shortId} with priority ${sortedEvaluations[index].priority}`
|
|
|
|
);
|
|
|
|
});
|
2018-07-07 00:07:53 +00:00
|
|
|
});
|
2018-11-06 00:06:08 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when the job for the evaluations is not found, an error message is shown, but the URL persists', async function(assert) {
|
|
|
|
await Evaluations.visit({ id: 'not-a-real-job' });
|
2018-11-06 00:06:08 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2020-01-20 20:57:01 +00:00
|
|
|
server.pretender.handledRequests
|
|
|
|
.filter(request => !request.url.includes('policy'))
|
|
|
|
.findBy('status', 404).url,
|
2018-11-06 00:06:08 +00:00
|
|
|
'/v1/job/not-a-real-job',
|
|
|
|
'A request to the nonexistent job is made'
|
|
|
|
);
|
|
|
|
assert.equal(currentURL(), '/jobs/not-a-real-job/evaluations', 'The URL persists');
|
|
|
|
assert.ok(Evaluations.error.isPresent, 'Error message is shown');
|
|
|
|
assert.equal(Evaluations.error.title, 'Not Found', 'Error message is for 404');
|
|
|
|
});
|
|
|
|
});
|