2021-12-28 19:30:38 +00:00
|
|
|
/* eslint-disable qunit/require-expect */
|
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-24 04:54:23 +00:00
|
|
|
import Allocations from 'nomad-ui/tests/pages/jobs/job/allocations';
|
|
|
|
|
|
|
|
let job;
|
|
|
|
let allocations;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const makeSearchAllocations = (server) => {
|
2018-07-30 19:56:42 +00:00
|
|
|
Array(10)
|
|
|
|
.fill(null)
|
|
|
|
.map((_, index) => {
|
|
|
|
server.create('allocation', {
|
|
|
|
id: index < 5 ? `ffffff-dddddd-${index}` : `111111-222222-${index}`,
|
2019-04-12 03:08:43 +00:00
|
|
|
shallow: true,
|
2018-07-30 19:56:42 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | job allocations', function (hooks) {
|
2019-03-13 00:04:16 +00:00
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2018-07-24 04:54:23 +00:00
|
|
|
server.create('node');
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
job = server.create('job', {
|
|
|
|
noFailedPlacements: true,
|
|
|
|
createAllocations: false,
|
|
|
|
});
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2018-07-24 04:54:23 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
2021-12-28 16:08:12 +00:00
|
|
|
server.createList('allocation', Allocations.pageSize - 1, {
|
|
|
|
shallow: true,
|
|
|
|
});
|
2020-07-28 17:59:14 +00:00
|
|
|
allocations = server.schema.allocations.where({ jobId: job.id }).models;
|
|
|
|
|
|
|
|
await Allocations.visit({ id: job.id });
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('lists all allocations for the job', async function (assert) {
|
2021-12-28 16:08:12 +00:00
|
|
|
server.createList('allocation', Allocations.pageSize - 1, {
|
|
|
|
shallow: true,
|
|
|
|
});
|
2019-03-13 00:04:16 +00:00
|
|
|
allocations = server.schema.allocations.where({ jobId: job.id }).models;
|
2018-07-24 04:54:23 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Allocations.visit({ id: job.id });
|
2018-07-24 04:54:23 +00:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
Allocations.allocations.length,
|
|
|
|
Allocations.pageSize - 1,
|
|
|
|
'Allocations are shown in a table'
|
|
|
|
);
|
|
|
|
|
|
|
|
const sortedAllocations = allocations.sortBy('modifyIndex').reverse();
|
|
|
|
|
|
|
|
Allocations.allocations.forEach((allocation, index) => {
|
|
|
|
const shortId = sortedAllocations[index].id.split('-')[0];
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
allocation.shortId,
|
|
|
|
shortId,
|
|
|
|
`Allocation ${index} is ${shortId}`
|
|
|
|
);
|
2018-07-24 04:54:23 +00:00
|
|
|
});
|
2019-07-17 20:02:58 +00:00
|
|
|
|
|
|
|
assert.equal(document.title, `Job ${job.name} allocations - Nomad`);
|
2018-07-24 04:54:23 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('allocations table is sortable', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('allocation', Allocations.pageSize - 1);
|
|
|
|
allocations = server.schema.allocations.where({ jobId: job.id }).models;
|
2018-07-24 04:54:23 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Allocations.visit({ id: job.id });
|
|
|
|
await Allocations.sortBy('taskGroupName');
|
2018-07-24 04:54:23 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/jobs/${job.id}/allocations?sort=taskGroupName`,
|
|
|
|
'the URL persists the sort parameter'
|
|
|
|
);
|
|
|
|
const sortedAllocations = allocations.sortBy('taskGroup').reverse();
|
|
|
|
Allocations.allocations.forEach((allocation, index) => {
|
|
|
|
const shortId = sortedAllocations[index].id.split('-')[0];
|
2018-07-24 04:54:23 +00:00
|
|
|
assert.equal(
|
2019-03-13 00:04:16 +00:00
|
|
|
allocation.shortId,
|
|
|
|
shortId,
|
|
|
|
`Allocation ${index} is ${shortId} with task group ${sortedAllocations[index].taskGroup}`
|
2018-07-24 04:54:23 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('allocations table is searchable', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
makeSearchAllocations(server);
|
2018-07-24 04:54:23 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
allocations = server.schema.allocations.where({ jobId: job.id }).models;
|
2018-07-24 04:54:23 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Allocations.visit({ id: job.id });
|
|
|
|
await Allocations.search('ffffff');
|
2018-07-24 04:54:23 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
Allocations.allocations.length,
|
|
|
|
5,
|
|
|
|
'List is filtered by search term'
|
|
|
|
);
|
2018-07-24 04:54:23 +00:00
|
|
|
});
|
2018-07-30 19:56:42 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when a search yields no results, the search box remains', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
makeSearchAllocations(server);
|
2018-07-30 19:56:42 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
allocations = server.schema.allocations.where({ jobId: job.id }).models;
|
2018-07-30 19:56:42 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Allocations.visit({ id: job.id });
|
|
|
|
await Allocations.search('^nothing will ever match this long regex$');
|
|
|
|
|
2018-07-30 19:56:42 +00:00
|
|
|
assert.equal(
|
|
|
|
Allocations.emptyState.headline,
|
|
|
|
'No Matches',
|
|
|
|
'List is empty and the empty state is about search'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.ok(Allocations.hasSearchBox, 'Search box is still shown');
|
|
|
|
});
|
2018-11-06 00:06:08 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the job for the allocations is not found, an error message is shown, but the URL persists', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await Allocations.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
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((request) => !request.url.includes('policy'))
|
2020-01-20 20:57:01 +00:00
|
|
|
.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'
|
|
|
|
);
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
'/jobs/not-a-real-job/allocations',
|
|
|
|
'The URL persists'
|
|
|
|
);
|
2018-11-06 00:06:08 +00:00
|
|
|
assert.ok(Allocations.error.isPresent, 'Error message is shown');
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
Allocations.error.title,
|
|
|
|
'Not Found',
|
|
|
|
'Error message is for 404'
|
|
|
|
);
|
2018-11-06 00:06:08 +00:00
|
|
|
});
|
2021-12-18 00:49:05 +00:00
|
|
|
|
|
|
|
testFacet('Status', {
|
|
|
|
facet: Allocations.facets.status,
|
|
|
|
paramName: 'status',
|
2022-04-22 15:25:02 +00:00
|
|
|
expectedOptions: [
|
|
|
|
'Pending',
|
|
|
|
'Running',
|
|
|
|
'Complete',
|
|
|
|
'Failed',
|
|
|
|
'Lost',
|
|
|
|
'Unknown',
|
|
|
|
],
|
2021-12-18 00:49:05 +00:00
|
|
|
async beforeEach() {
|
2022-04-22 15:25:02 +00:00
|
|
|
['pending', 'running', 'complete', 'failed', 'lost', 'unknown'].forEach(
|
|
|
|
(s) => {
|
|
|
|
server.createList('allocation', 5, { clientStatus: s });
|
|
|
|
}
|
|
|
|
);
|
2021-12-18 00:49:05 +00:00
|
|
|
await Allocations.visit({ id: job.id });
|
|
|
|
},
|
2021-12-28 16:08:12 +00:00
|
|
|
filter: (alloc, selection) =>
|
|
|
|
alloc.jobId == job.id && selection.includes(alloc.clientStatus),
|
2021-12-18 00:49:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testFacet('Client', {
|
|
|
|
facet: Allocations.facets.client,
|
|
|
|
paramName: 'client',
|
|
|
|
expectedOptions(allocs) {
|
|
|
|
return Array.from(
|
|
|
|
new Set(
|
|
|
|
allocs
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((alloc) => alloc.jobId == job.id)
|
2021-12-18 00:49:05 +00:00
|
|
|
.mapBy('nodeId')
|
2021-12-28 14:45:20 +00:00
|
|
|
.map((id) => id.split('-')[0])
|
2021-12-18 00:49:05 +00:00
|
|
|
)
|
|
|
|
).sort();
|
|
|
|
},
|
|
|
|
async beforeEach() {
|
|
|
|
server.createList('node', 5);
|
|
|
|
server.createList('allocation', 20);
|
|
|
|
|
|
|
|
await Allocations.visit({ id: job.id });
|
|
|
|
},
|
|
|
|
filter: (alloc, selection) =>
|
|
|
|
alloc.jobId == job.id && selection.includes(alloc.nodeId.split('-')[0]),
|
|
|
|
});
|
|
|
|
|
|
|
|
testFacet('Task Group', {
|
|
|
|
facet: Allocations.facets.taskGroup,
|
|
|
|
paramName: 'taskGroup',
|
|
|
|
expectedOptions(allocs) {
|
|
|
|
return Array.from(
|
2021-12-28 16:08:12 +00:00
|
|
|
new Set(
|
|
|
|
allocs.filter((alloc) => alloc.jobId == job.id).mapBy('taskGroup')
|
|
|
|
)
|
2021-12-18 00:49:05 +00:00
|
|
|
).sort();
|
|
|
|
},
|
|
|
|
async beforeEach() {
|
|
|
|
job = server.create('job', {
|
|
|
|
type: 'service',
|
|
|
|
status: 'running',
|
|
|
|
groupsCount: 5,
|
|
|
|
});
|
|
|
|
|
|
|
|
await Allocations.visit({ id: job.id });
|
|
|
|
},
|
2021-12-28 16:08:12 +00:00
|
|
|
filter: (alloc, selection) =>
|
|
|
|
alloc.jobId == job.id && selection.includes(alloc.taskGroup),
|
2021-12-18 00:49:05 +00:00
|
|
|
});
|
2018-11-06 00:06:08 +00:00
|
|
|
});
|
2021-12-18 00:49:05 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
function testFacet(
|
|
|
|
label,
|
|
|
|
{ facet, paramName, beforeEach, filter, expectedOptions }
|
|
|
|
) {
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`facet ${label} | the ${label} facet has the correct options`, async function (assert) {
|
2021-12-18 00:49:05 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
let expectation;
|
|
|
|
if (typeof expectedOptions === 'function') {
|
|
|
|
expectation = expectedOptions(server.db.allocations);
|
|
|
|
} else {
|
|
|
|
expectation = expectedOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual(
|
2021-12-28 14:45:20 +00:00
|
|
|
facet.options.map((option) => option.label.trim()),
|
2021-12-18 00:49:05 +00:00
|
|
|
expectation,
|
|
|
|
'Options for facet are as expected'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`facet ${label} | the ${label} facet filters the allocations list by ${label}`, async function (assert) {
|
2021-12-18 00:49:05 +00:00
|
|
|
let option;
|
|
|
|
|
|
|
|
await beforeEach();
|
|
|
|
|
|
|
|
await facet.toggle();
|
|
|
|
option = facet.options.objectAt(0);
|
|
|
|
await option.toggle();
|
|
|
|
|
|
|
|
const selection = [option.key];
|
|
|
|
const expectedAllocs = server.db.allocations
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((alloc) => filter(alloc, selection))
|
2021-12-18 00:49:05 +00:00
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse();
|
|
|
|
|
|
|
|
Allocations.allocations.forEach((alloc, index) => {
|
|
|
|
assert.equal(
|
|
|
|
alloc.id,
|
|
|
|
expectedAllocs[index].id,
|
|
|
|
`Allocation at ${index} is ${expectedAllocs[index].id}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`facet ${label} | selecting multiple options in the ${label} facet results in a broader search`, async function (assert) {
|
2021-12-18 00:49:05 +00:00
|
|
|
const selection = [];
|
|
|
|
|
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
const option1 = facet.options.objectAt(0);
|
|
|
|
const option2 = facet.options.objectAt(1);
|
|
|
|
await option1.toggle();
|
|
|
|
selection.push(option1.key);
|
|
|
|
await option2.toggle();
|
|
|
|
selection.push(option2.key);
|
|
|
|
|
|
|
|
const expectedAllocs = server.db.allocations
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((alloc) => filter(alloc, selection))
|
2021-12-18 00:49:05 +00:00
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse();
|
|
|
|
|
|
|
|
Allocations.allocations.forEach((alloc, index) => {
|
|
|
|
assert.equal(
|
|
|
|
alloc.id,
|
|
|
|
expectedAllocs[index].id,
|
|
|
|
`Allocation at ${index} is ${expectedAllocs[index].id}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`facet ${label} | selecting options in the ${label} facet updates the ${paramName} query param`, async function (assert) {
|
2021-12-18 00:49:05 +00:00
|
|
|
const selection = [];
|
|
|
|
|
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
const option1 = facet.options.objectAt(0);
|
|
|
|
const option2 = facet.options.objectAt(1);
|
|
|
|
await option1.toggle();
|
|
|
|
selection.push(option1.key);
|
|
|
|
await option2.toggle();
|
|
|
|
selection.push(option2.key);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
2021-12-28 16:08:12 +00:00
|
|
|
`/jobs/${job.id}/allocations?${paramName}=${encodeURIComponent(
|
|
|
|
JSON.stringify(selection)
|
|
|
|
)}`,
|
2021-12-18 00:49:05 +00:00
|
|
|
'URL has the correct query param key and value'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|