open-nomad/ui/tests/acceptance/job-allocations-test.js

112 lines
3.6 KiB
JavaScript
Raw Normal View History

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';
import Allocations from 'nomad-ui/tests/pages/jobs/job/allocations';
let job;
let allocations;
const makeSearchAllocations = server => {
Array(10)
.fill(null)
.map((_, index) => {
server.create('allocation', {
id: index < 5 ? `ffffff-dddddd-${index}` : `111111-222222-${index}`,
});
});
};
2019-03-13 00:04:16 +00:00
module('Acceptance | job allocations', function(hooks) {
setupApplicationTest(hooks);
hooks.beforeEach(function() {
server.create('node');
job = server.create('job', { noFailedPlacements: true, createAllocations: false });
2019-03-13 00:04:16 +00:00
});
2019-03-13 00:04:16 +00:00
test('lists all allocations for the job', function(assert) {
server.createList('allocation', Allocations.pageSize - 1);
allocations = server.schema.allocations.where({ jobId: job.id }).models;
2019-03-13 00:04:16 +00:00
Allocations.visit({ id: job.id });
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];
assert.equal(allocation.shortId, shortId, `Allocation ${index} is ${shortId}`);
});
});
2019-03-13 00:04:16 +00:00
test('allocations table is sortable', function(assert) {
server.createList('allocation', Allocations.pageSize - 1);
allocations = server.schema.allocations.where({ jobId: job.id }).models;
2019-03-13 00:04:16 +00:00
Allocations.visit({ id: job.id });
Allocations.sortBy('taskGroupName');
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];
assert.equal(
2019-03-13 00:04:16 +00:00
allocation.shortId,
shortId,
`Allocation ${index} is ${shortId} with task group ${sortedAllocations[index].taskGroup}`
);
});
});
2019-03-13 00:04:16 +00:00
test('allocations table is searchable', function(assert) {
makeSearchAllocations(server);
2019-03-13 00:04:16 +00:00
allocations = server.schema.allocations.where({ jobId: job.id }).models;
Allocations.visit({ id: job.id });
Allocations.search('ffffff');
assert.equal(Allocations.allocations.length, 5, 'List is filtered by search term');
});
2019-03-13 00:04:16 +00:00
test('when a search yields no results, the search box remains', function(assert) {
makeSearchAllocations(server);
2019-03-13 00:04:16 +00:00
allocations = server.schema.allocations.where({ jobId: job.id }).models;
Allocations.visit({ id: job.id });
Allocations.search('^nothing will ever match this long regex$');
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');
});
2019-03-13 00:04:16 +00:00
test('when the job for the allocations is not found, an error message is shown, but the URL persists', function(assert) {
Allocations.visit({ id: 'not-a-real-job' });
assert.equal(
server.pretender.handledRequests.findBy('status', 404).url,
'/v1/job/not-a-real-job',
'A request to the nonexistent job is made'
);
assert.equal(currentURL(), '/jobs/not-a-real-job/allocations', 'The URL persists');
assert.ok(Allocations.error.isPresent, 'Error message is shown');
assert.equal(Allocations.error.title, 'Not Found', 'Error message is for 404');
});
});