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';
|
|
|
|
|
|
|
|
let allocation;
|
|
|
|
let task;
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | task detail', {
|
|
|
|
beforeEach() {
|
|
|
|
server.create('agent');
|
|
|
|
server.create('node');
|
|
|
|
server.create('job', { createAllocations: false });
|
2018-01-26 13:28:39 +00:00
|
|
|
allocation = server.create('allocation', 'withTaskWithPorts');
|
2017-10-31 04:02:40 +00:00
|
|
|
task = server.db.taskStates.where({ allocationId: allocation.id })[0];
|
|
|
|
|
|
|
|
visit(`/allocations/${allocation.id}/${task.name}`);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-01-26 13:28:39 +00:00
|
|
|
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'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-03-13 23:32:56 +00:00
|
|
|
test('breadcrumbs match jobs / job / task group / allocation / task', function(assert) {
|
|
|
|
const { jobId, taskGroup } = allocation;
|
|
|
|
const job = server.db.jobs.find(jobId);
|
|
|
|
|
|
|
|
const shortId = allocation.id.split('-')[0];
|
|
|
|
|
|
|
|
assert.equal(
|
2018-06-27 20:40:44 +00:00
|
|
|
find('[data-test-breadcrumb="jobs.index"]').textContent.trim(),
|
2018-03-13 23:32:56 +00:00
|
|
|
'Jobs',
|
|
|
|
'Jobs is the first breadcrumb'
|
|
|
|
);
|
2017-10-31 04:02:40 +00:00
|
|
|
assert.equal(
|
2018-06-27 20:40:44 +00:00
|
|
|
find('[data-test-breadcrumb="jobs.job.index"]').textContent.trim(),
|
2018-03-13 23:32:56 +00:00
|
|
|
job.name,
|
|
|
|
'Job is the second breadcrumb'
|
2017-10-31 04:02:40 +00:00
|
|
|
);
|
2017-12-20 01:25:35 +00:00
|
|
|
assert.equal(
|
2018-06-27 20:40:44 +00:00
|
|
|
find('[data-test-breadcrumb="jobs.job.task-group"]').textContent.trim(),
|
2018-03-13 23:32:56 +00:00
|
|
|
taskGroup,
|
|
|
|
'Task Group is the third breadcrumb'
|
2017-10-31 04:02:40 +00:00
|
|
|
);
|
|
|
|
assert.equal(
|
2018-06-27 20:40:44 +00:00
|
|
|
find('[data-test-breadcrumb="allocations.allocation"]').textContent.trim(),
|
2018-03-13 23:32:56 +00:00
|
|
|
shortId,
|
|
|
|
'Allocation short id is the fourth breadcrumb'
|
2017-10-31 04:02:40 +00:00
|
|
|
);
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(
|
2018-06-27 20:40:44 +00:00
|
|
|
find('[data-test-breadcrumb="allocations.allocation.task"]').textContent.trim(),
|
2018-01-05 20:59:36 +00:00
|
|
|
task.name,
|
2018-03-13 23:32:56 +00:00
|
|
|
'Task name is the fifth breadcrumb'
|
2018-01-05 20:59:36 +00:00
|
|
|
);
|
2017-10-31 04:02:40 +00:00
|
|
|
|
2018-06-27 20:40:44 +00:00
|
|
|
click('[data-test-breadcrumb="jobs.index"]');
|
2018-03-13 23:32:56 +00:00
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/jobs', 'Jobs breadcrumb links correctly');
|
|
|
|
});
|
|
|
|
andThen(() => {
|
|
|
|
visit(`/allocations/${allocation.id}/${task.name}`);
|
|
|
|
});
|
|
|
|
andThen(() => {
|
2018-06-27 20:40:44 +00:00
|
|
|
click('[data-test-breadcrumb="jobs.job.index"]');
|
2018-03-13 23:32:56 +00:00
|
|
|
});
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}`, 'Job breadcrumb links correctly');
|
|
|
|
});
|
|
|
|
andThen(() => {
|
|
|
|
visit(`/allocations/${allocation.id}/${task.name}`);
|
|
|
|
});
|
|
|
|
andThen(() => {
|
2018-06-27 20:40:44 +00:00
|
|
|
click('[data-test-breadcrumb="jobs.job.task-group"]');
|
2018-03-13 23:32:56 +00:00
|
|
|
});
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/jobs/${job.id}/${taskGroup}`,
|
|
|
|
'Task Group breadcrumb links correctly'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
andThen(() => {
|
|
|
|
visit(`/allocations/${allocation.id}/${task.name}`);
|
|
|
|
});
|
|
|
|
andThen(() => {
|
2018-06-27 20:40:44 +00:00
|
|
|
click('[data-test-breadcrumb="allocations.allocation"]');
|
2018-03-13 23:32:56 +00:00
|
|
|
});
|
2017-10-31 04:02:40 +00:00
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/allocations/${allocation.id}`,
|
2018-03-13 23:32:56 +00:00
|
|
|
'Allocations breadcrumb links correctly'
|
2017-10-31 04:02:40 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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 taskResources = allocation.taskResourcesIds
|
|
|
|
.map(id => server.db.taskResources.find(id))
|
|
|
|
.findBy('name', task.name);
|
2018-06-04 22:34:16 +00:00
|
|
|
const networkAddress = taskResources.resources.Networks[0].IP;
|
2017-10-31 04:02:40 +00:00
|
|
|
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(),
|
2018-06-04 22:34:16 +00:00
|
|
|
`${networkAddress}:${address.Value}`,
|
2017-10-31 04:02:40 +00:00
|
|
|
'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`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-01-26 13:28:39 +00:00
|
|
|
test('each recent event should list the time, type, and description of the event', function(assert) {
|
2017-10-31 04:02:40 +00:00
|
|
|
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(),
|
2018-03-28 19:52:02 +00:00
|
|
|
event.displayMessage,
|
2017-10-31 04:02:40 +00:00
|
|
|
'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',
|
2018-03-12 18:26:37 +00:00
|
|
|
'A request to the nonexistent allocation is made'
|
2017-10-31 04:02:40 +00:00
|
|
|
);
|
|
|
|
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
|
|
|
});
|