2017-12-15 21:39:18 +00:00
|
|
|
import $ from 'jquery';
|
2018-04-10 01:40:53 +00:00
|
|
|
import { click, findAll, currentURL, find, visit, waitFor } from 'ember-native-dom-helpers';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { test } from 'qunit';
|
|
|
|
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
let job;
|
|
|
|
let node;
|
|
|
|
let allocation;
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | allocation detail', {
|
|
|
|
beforeEach() {
|
|
|
|
server.create('agent');
|
|
|
|
|
|
|
|
node = server.create('node');
|
|
|
|
job = server.create('job', { groupCount: 0 });
|
2018-01-26 13:28:39 +00:00
|
|
|
allocation = server.create('allocation', 'withTaskWithPorts');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
visit(`/allocations/${allocation.id}`);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-01-26 13:28:39 +00:00
|
|
|
test('/allocation/:id should name the allocation and link to the corresponding job and node', function(assert) {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(
|
|
|
|
find('[data-test-title]').textContent.includes(allocation.name),
|
|
|
|
'Allocation name is in the heading'
|
|
|
|
);
|
2017-10-30 21:16:08 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-allocation-details] [data-test-job-link]').textContent.trim(),
|
2017-10-30 21:16:08 +00:00
|
|
|
job.name,
|
|
|
|
'Job name is in the subheading'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-allocation-details] [data-test-client-link]').textContent.trim(),
|
2017-10-30 21:16:08 +00:00
|
|
|
node.id.split('-')[0],
|
2017-09-19 14:47:10 +00:00
|
|
|
'Node short id is in the subheading'
|
|
|
|
);
|
|
|
|
|
2017-09-26 07:47:16 +00:00
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
click('[data-test-allocation-details] [data-test-job-link]');
|
2017-09-26 07:47:16 +00:00
|
|
|
});
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}`, 'Job link navigates to the job');
|
|
|
|
});
|
|
|
|
|
|
|
|
visit(`/allocations/${allocation.id}`);
|
2017-09-26 07:47:16 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
click('[data-test-allocation-details] [data-test-client-link]');
|
2017-09-26 07:47:16 +00:00
|
|
|
});
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
andThen(() => {
|
2017-10-28 01:23:41 +00:00
|
|
|
assert.equal(currentURL(), `/clients/${node.id}`, 'Client link navigates to the client');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('/allocation/:id should list all tasks for the allocation', function(assert) {
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
findAll('[data-test-task-row]').length,
|
2017-09-19 14:47:10 +00:00
|
|
|
server.db.taskStates.where({ allocationId: allocation.id }).length,
|
|
|
|
'Table lists all tasks'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each task row should list high-level information for the task', function(assert) {
|
|
|
|
const task = server.db.taskStates.where({ allocationId: allocation.id }).sortBy('name')[0];
|
|
|
|
const taskResources = allocation.taskResourcesIds
|
|
|
|
.map(id => server.db.taskResources.find(id))
|
|
|
|
.sortBy('name')[0];
|
|
|
|
const reservedPorts = taskResources.resources.Networks[0].ReservedPorts;
|
2017-10-31 04:02:40 +00:00
|
|
|
const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts;
|
2018-01-05 20:59:36 +00:00
|
|
|
const taskRow = $(findAll('[data-test-task-row]')[0]);
|
2017-09-19 14:47:10 +00:00
|
|
|
const events = server.db.taskEvents.where({ taskStateId: task.id });
|
|
|
|
const event = events[events.length - 1];
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
taskRow
|
2018-01-05 20:59:36 +00:00
|
|
|
.find('[data-test-name]')
|
2017-09-19 14:47:10 +00:00
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
task.name,
|
|
|
|
'Name'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskRow
|
2018-01-05 20:59:36 +00:00
|
|
|
.find('[data-test-state]')
|
2017-09-19 14:47:10 +00:00
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
task.state,
|
|
|
|
'State'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskRow
|
2018-01-05 20:59:36 +00:00
|
|
|
.find('[data-test-message]')
|
2017-09-19 14:47:10 +00:00
|
|
|
.text()
|
|
|
|
.trim(),
|
2018-03-28 19:52:02 +00:00
|
|
|
event.displayMessage,
|
2017-09-19 14:47:10 +00:00
|
|
|
'Event Message'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskRow
|
2018-01-05 20:59:36 +00:00
|
|
|
.find('[data-test-time]')
|
2017-09-19 14:47:10 +00:00
|
|
|
.text()
|
|
|
|
.trim(),
|
2017-12-06 03:12:18 +00:00
|
|
|
moment(event.time / 1000000).format('MM/DD/YY HH:mm:ss'),
|
2017-09-19 14:47:10 +00:00
|
|
|
'Event Time'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.ok(reservedPorts.length, 'The task has reserved ports');
|
2017-10-31 04:02:40 +00:00
|
|
|
assert.ok(dynamicPorts.length, 'The task has dynamic ports');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
const addressesText = taskRow.find('[data-test-ports]').text();
|
2017-09-19 14:47:10 +00:00
|
|
|
reservedPorts.forEach(port => {
|
|
|
|
assert.ok(addressesText.includes(port.Label), `Found label ${port.Label}`);
|
|
|
|
assert.ok(addressesText.includes(port.Value), `Found value ${port.Value}`);
|
|
|
|
});
|
2017-10-31 04:02:40 +00:00
|
|
|
dynamicPorts.forEach(port => {
|
|
|
|
assert.ok(addressesText.includes(port.Label), `Found label ${port.Label}`);
|
|
|
|
assert.ok(addressesText.includes(port.Value), `Found value ${port.Value}`);
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
2017-09-29 00:05:41 +00:00
|
|
|
|
2018-01-26 13:28:39 +00:00
|
|
|
test('when the allocation is not found, an error message is shown, but the URL persists', function(assert) {
|
2017-09-29 00:05:41 +00:00
|
|
|
visit('/allocations/not-a-real-allocation');
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
server.pretender.handledRequests.findBy('status', 404).url,
|
|
|
|
'/v1/allocation/not-a-real-allocation',
|
2018-03-12 18:26:37 +00:00
|
|
|
'A request to the nonexistent allocation is made'
|
2017-09-29 00:05:41 +00:00
|
|
|
);
|
|
|
|
assert.equal(currentURL(), '/allocations/not-a-real-allocation', 'The URL persists');
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(find('[data-test-error]'), 'Error message is shown');
|
2017-09-29 00:05:41 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-error-title]').textContent,
|
2017-09-29 00:05:41 +00:00
|
|
|
'Not Found',
|
|
|
|
'Error message is for 404'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-04-10 01:40:53 +00:00
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | allocation detail (loading states)', {
|
|
|
|
beforeEach() {
|
|
|
|
server.create('agent');
|
|
|
|
|
|
|
|
node = server.create('node');
|
|
|
|
job = server.create('job', { groupCount: 0 });
|
|
|
|
allocation = server.create('allocation', 'withTaskWithPorts');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when the node the allocation is on has yet to load, address links are in a loading state', function(assert) {
|
|
|
|
server.get('/node/:id', { timing: true });
|
|
|
|
|
|
|
|
visit(`/allocations/${allocation.id}`);
|
|
|
|
|
|
|
|
waitFor('[data-test-port]').then(() => {
|
|
|
|
assert.ok(
|
|
|
|
find('[data-test-port]')
|
|
|
|
.textContent.trim()
|
|
|
|
.endsWith('...'),
|
|
|
|
'The address is in a loading state'
|
|
|
|
);
|
|
|
|
assert.notOk(
|
|
|
|
find('[data-test-port]').querySelector('a'),
|
|
|
|
'While in the loading state, there is no link to the address'
|
|
|
|
);
|
|
|
|
|
|
|
|
server.pretender.requestReferences.forEach(({ request }) => {
|
|
|
|
server.pretender.resolve(request);
|
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const taskResources = allocation.taskResourcesIds
|
|
|
|
.map(id => server.db.taskResources.find(id))
|
|
|
|
.sortBy('name')[0];
|
|
|
|
const port = taskResources.resources.Networks[0].ReservedPorts[0];
|
|
|
|
const addressText = find('[data-test-port]').textContent.trim();
|
|
|
|
|
|
|
|
assert.ok(addressText.includes(port.Label), `Found label ${port.Label}`);
|
|
|
|
assert.ok(addressText.includes(port.Value), `Found value ${port.Value}`);
|
|
|
|
assert.ok(addressText.includes(node.httpAddr.match(/(.+):.+$/)[1]), 'Found the node address');
|
|
|
|
assert.ok(find('[data-test-port]').querySelector('a'), 'Link to address found');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|