2017-10-31 04:02:40 +00:00
|
|
|
import { click, findAll, currentURL, find, visit } from 'ember-native-dom-helpers';
|
|
|
|
import { test } from 'qunit';
|
|
|
|
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
|
|
|
|
import moment from 'moment';
|
|
|
|
import ipParts from 'nomad-ui/utils/ip-parts';
|
|
|
|
|
|
|
|
let allocation;
|
|
|
|
let task;
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | task detail', {
|
|
|
|
beforeEach() {
|
|
|
|
server.create('agent');
|
|
|
|
server.create('node');
|
|
|
|
server.create('job', { createAllocations: false });
|
|
|
|
allocation = server.create('allocation', 'withTaskWithPorts', {
|
|
|
|
useMessagePassthru: true,
|
|
|
|
});
|
|
|
|
task = server.db.taskStates.where({ allocationId: allocation.id })[0];
|
|
|
|
|
|
|
|
visit(`/allocations/${allocation.id}/${task.name}`);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('/allocation/:id/:task_name should name the task and list high-level task information', function(
|
|
|
|
assert
|
|
|
|
) {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(find('[data-test-title]').textContent.includes(task.name), 'Task name');
|
|
|
|
assert.ok(find('[data-test-state]').textContent.includes(task.state), 'Task state');
|
2017-10-31 04:02:40 +00:00
|
|
|
|
|
|
|
assert.ok(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-started-at]').textContent.includes(
|
|
|
|
moment(task.startedAt).format('MM/DD/YY HH:mm:ss')
|
|
|
|
),
|
2017-10-31 04:02:40 +00:00
|
|
|
'Task started at'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('breadcrumbs includes allocations and link to the allocation detail page', function(assert) {
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-breadcrumb="allocations"]').textContent.trim(),
|
2017-10-31 04:02:40 +00:00
|
|
|
'Allocations',
|
|
|
|
'Allocations is the first breadcrumb'
|
|
|
|
);
|
2017-12-20 01:25:35 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-breadcrumb="allocations"]').getAttribute('href'),
|
2017-12-20 01:25:35 +00:00
|
|
|
'#',
|
|
|
|
"Allocations breadcrumb doesn't link anywhere"
|
2017-10-31 04:02:40 +00:00
|
|
|
);
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-breadcrumb="allocation"]').textContent.trim(),
|
2017-10-31 04:02:40 +00:00
|
|
|
allocation.id.split('-')[0],
|
|
|
|
'Allocation short id is the second breadcrumb'
|
|
|
|
);
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(
|
|
|
|
find('[data-test-breadcrumb="task"]').textContent.trim(),
|
|
|
|
task.name,
|
|
|
|
'Task name is the third breadcrumb'
|
|
|
|
);
|
2017-10-31 04:02:40 +00:00
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
click('[data-test-breadcrumb="allocation"]');
|
2017-10-31 04:02:40 +00:00
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/allocations/${allocation.id}`,
|
|
|
|
'Second breadcrumb links back to the allocation detail'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the addresses table lists all reserved and dynamic ports', function(assert) {
|
|
|
|
const taskResources = allocation.taskResourcesIds
|
|
|
|
.map(id => server.db.taskResources.find(id))
|
2017-11-17 01:35:02 +00:00
|
|
|
.find(resources => resources.name === task.name);
|
2017-10-31 04:02:40 +00:00
|
|
|
const reservedPorts = taskResources.resources.Networks[0].ReservedPorts;
|
|
|
|
const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts;
|
|
|
|
const addresses = reservedPorts.concat(dynamicPorts);
|
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
findAll('[data-test-task-address]').length,
|
2017-10-31 04:02:40 +00:00
|
|
|
addresses.length,
|
|
|
|
'All addresses are listed'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each address row shows the label and value of the address', function(assert) {
|
|
|
|
const node = server.db.nodes.find(allocation.nodeId);
|
|
|
|
const taskResources = allocation.taskResourcesIds
|
|
|
|
.map(id => server.db.taskResources.find(id))
|
|
|
|
.findBy('name', task.name);
|
|
|
|
const reservedPorts = taskResources.resources.Networks[0].ReservedPorts;
|
|
|
|
const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts;
|
|
|
|
const address = reservedPorts.concat(dynamicPorts).sortBy('Label')[0];
|
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
const addressRow = find('[data-test-task-address]');
|
2017-10-31 04:02:40 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
addressRow.querySelector('[data-test-task-address-is-dynamic]').textContent.trim(),
|
2017-10-31 04:02:40 +00:00
|
|
|
reservedPorts.includes(address) ? 'No' : 'Yes',
|
|
|
|
'Dynamic port is denoted as such'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
addressRow.querySelector('[data-test-task-address-name]').textContent.trim(),
|
2017-10-31 04:02:40 +00:00
|
|
|
address.Label,
|
|
|
|
'Label'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
addressRow.querySelector('[data-test-task-address-address]').textContent.trim(),
|
2017-10-31 04:02:40 +00:00
|
|
|
`${ipParts(node.httpAddr).address}:${address.Value}`,
|
|
|
|
'Value'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the events table lists all recent events', function(assert) {
|
|
|
|
const events = server.db.taskEvents.where({ taskStateId: task.id });
|
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
findAll('[data-test-task-event]').length,
|
2017-10-31 04:02:40 +00:00
|
|
|
events.length,
|
|
|
|
`Lists ${events.length} events`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each recent event should list the time, type, and description of the event', function(
|
|
|
|
assert
|
|
|
|
) {
|
|
|
|
const event = server.db.taskEvents.where({ taskStateId: task.id })[0];
|
2018-01-05 20:59:36 +00:00
|
|
|
const recentEvent = findAll('[data-test-task-event]').get('lastObject');
|
2017-10-31 04:02:40 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
recentEvent.querySelector('[data-test-task-event-time]').textContent.trim(),
|
2017-10-31 04:02:40 +00:00
|
|
|
moment(event.time / 1000000).format('MM/DD/YY HH:mm:ss'),
|
|
|
|
'Event timestamp'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
recentEvent.querySelector('[data-test-task-event-type]').textContent.trim(),
|
2017-10-31 04:02:40 +00:00
|
|
|
event.type,
|
|
|
|
'Event type'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
recentEvent.querySelector('[data-test-task-event-message]').textContent.trim(),
|
2017-10-31 04:02:40 +00:00
|
|
|
event.message,
|
|
|
|
'Event message'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when the allocation is not found, the application errors', function(assert) {
|
|
|
|
visit(`/allocations/not-a-real-allocation/${task.name}`);
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
server.pretender.handledRequests.findBy('status', 404).url,
|
|
|
|
'/v1/allocation/not-a-real-allocation',
|
|
|
|
'A request to the non-existent allocation is made'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/allocations/not-a-real-allocation/${task.name}`,
|
|
|
|
'The URL persists'
|
|
|
|
);
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(find('[data-test-error]'), 'Error message is shown');
|
2017-10-31 04:02:40 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-error-title]').textContent,
|
2017-10-31 04:02:40 +00:00
|
|
|
'Not Found',
|
|
|
|
'Error message is for 404'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when the allocation is found but the task is not, the application errors', function(assert) {
|
|
|
|
visit(`/allocations/${allocation.id}/not-a-real-task-name`);
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
server.pretender.handledRequests.findBy('status', 200).url,
|
|
|
|
`/v1/allocation/${allocation.id}`,
|
|
|
|
'A request to the allocation is made successfully'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/allocations/${allocation.id}/not-a-real-task-name`,
|
|
|
|
'The URL persists'
|
|
|
|
);
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(find('[data-test-error]'), 'Error message is shown');
|
2017-10-31 04:02:40 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-error-title]').textContent,
|
2017-10-31 04:02:40 +00:00
|
|
|
'Not Found',
|
|
|
|
'Error message is for 404'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | task detail (no addresses)', {
|
|
|
|
beforeEach() {
|
|
|
|
server.create('agent');
|
|
|
|
server.create('node');
|
|
|
|
server.create('job');
|
|
|
|
allocation = server.create('allocation', 'withoutTaskWithPorts');
|
|
|
|
task = server.db.taskStates.where({ allocationId: allocation.id })[0];
|
|
|
|
|
|
|
|
visit(`/allocations/${allocation.id}/${task.name}`);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when the task has no addresses, the addresses table is not shown', function(assert) {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.notOk(find('[data-test-task-addresses]'), 'No addresses table');
|
2017-10-31 04:02:40 +00:00
|
|
|
});
|