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

302 lines
9 KiB
JavaScript
Raw Normal View History

import { click, findAll, currentURL, find, visit } from 'ember-native-dom-helpers';
2017-09-19 14:47:10 +00:00
import Ember from 'ember';
import moment from 'moment';
import { test } from 'qunit';
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
const { get, $ } = Ember;
2017-09-19 14:47:10 +00:00
const sum = (list, key) => list.reduce((sum, item) => sum + get(item, key), 0);
let job;
moduleForAcceptance('Acceptance | job detail', {
beforeEach() {
server.create('node');
server.create('job');
job = server.db.jobs[0];
visit(`/jobs/${job.id}`);
},
});
test('visiting /jobs/:job_id', function(assert) {
assert.equal(currentURL(), `/jobs/${job.id}`);
});
test('breadcrumbs includes job name and link back to the jobs list', function(assert) {
assert.equal(findAll('.breadcrumb')[0].textContent, 'Jobs', 'First breadcrumb says jobs');
assert.equal(
findAll('.breadcrumb')[1].textContent,
job.name,
'Second breadcrumb says the job name'
);
2017-09-19 14:47:10 +00:00
click(findAll('.breadcrumb')[0]);
2017-09-19 14:47:10 +00:00
andThen(() => {
assert.equal(currentURL(), '/jobs', 'First breadcrumb links back to jobs');
});
});
test('the job detail page should contain basic information about the job', function(assert) {
assert.ok(findAll('.title .tag')[0].textContent.includes(job.status), 'Status');
assert.ok(findAll('.job-stats span')[0].textContent.includes(job.type), 'Type');
assert.ok(findAll('.job-stats span')[1].textContent.includes(job.priority), 'Priority');
2017-10-11 17:12:10 +00:00
assert.notOk(findAll('.job-stats span')[2], 'Namespace is not included');
2017-09-19 14:47:10 +00:00
});
test('the job detail page should list all task groups', function(assert) {
assert.equal(
findAll('.task-group-row').length,
2017-09-19 14:47:10 +00:00
server.db.taskGroups.where({ jobId: job.id }).length
);
});
test('each row in the task group table should show basic information about the task group', function(
assert
) {
const taskGroup = job.taskGroupIds.map(id => server.db.taskGroups.find(id)).sortBy('name')[0];
const taskGroupRow = $(findAll('.task-group-row')[0]);
2017-09-19 14:47:10 +00:00
const tasks = server.db.tasks.where({ taskGroupId: taskGroup.id });
const sum = (list, key) => list.reduce((sum, item) => sum + get(item, key), 0);
assert.equal(taskGroupRow.find('td:eq(0)').text(), taskGroup.name, 'Name');
assert.equal(taskGroupRow.find('td:eq(1)').text(), taskGroup.count, 'Count');
assert.equal(
taskGroupRow.find('td:eq(3)').text(),
`${sum(tasks, 'Resources.CPU')} MHz`,
'Reserved CPU'
);
assert.equal(
taskGroupRow.find('td:eq(4)').text(),
`${sum(tasks, 'Resources.MemoryMB')} MiB`,
'Reserved Memory'
);
assert.equal(
taskGroupRow.find('td:eq(5)').text(),
`${taskGroup.ephemeralDisk.SizeMB} MiB`,
'Reserved Disk'
);
});
test('the allocations diagram lists all allocation status figures', function(assert) {
const legend = find('.distribution-bar .legend');
const jobSummary = server.db.jobSummaries.findBy({ jobId: job.id });
const statusCounts = Object.keys(jobSummary.Summary).reduce(
(counts, key) => {
const group = jobSummary.Summary[key];
counts.queued += group.Queued;
counts.starting += group.Starting;
counts.running += group.Running;
counts.complete += group.Complete;
counts.failed += group.Failed;
counts.lost += group.Lost;
return counts;
},
{ queued: 0, starting: 0, running: 0, complete: 0, failed: 0, lost: 0 }
);
assert.equal(
legend.querySelector('li.queued .value').textContent,
2017-09-19 14:47:10 +00:00
statusCounts.queued,
`${statusCounts.queued} are queued`
);
assert.equal(
legend.querySelector('li.starting .value').textContent,
2017-09-19 14:47:10 +00:00
statusCounts.starting,
`${statusCounts.starting} are starting`
);
assert.equal(
legend.querySelector('li.running .value').textContent,
2017-09-19 14:47:10 +00:00
statusCounts.running,
`${statusCounts.running} are running`
);
assert.equal(
legend.querySelector('li.complete .value').textContent,
2017-09-19 14:47:10 +00:00
statusCounts.complete,
`${statusCounts.complete} are complete`
);
assert.equal(
legend.querySelector('li.failed .value').textContent,
2017-09-19 14:47:10 +00:00
statusCounts.failed,
`${statusCounts.failed} are failed`
);
assert.equal(
legend.querySelector('li.lost .value').textContent,
2017-09-19 14:47:10 +00:00
statusCounts.lost,
`${statusCounts.lost} are lost`
);
});
test('there is no active deployment section when the job has no active deployment', function(
assert
) {
// TODO: it would be better to not visit two different job pages in one test, but this
// way is much more convenient.
job = server.create('job', { noActiveDeployment: true });
visit(`/jobs/${job.id}`);
andThen(() => {
assert.ok(findAll('.active-deployment').length === 0, 'No active deployment');
2017-09-19 14:47:10 +00:00
});
});
test('the active deployment section shows up for the currently running deployment', function(
assert
) {
job = server.create('job', { activeDeployment: true });
const deployment = server.db.deployments.where({ jobId: job.id })[0];
const taskGroupSummaries = server.db.deploymentTaskGroupSummaries.where({
deploymentId: deployment.id,
});
const version = server.db.jobVersions.findBy({
jobId: job.id,
version: deployment.versionNumber,
});
visit(`/jobs/${job.id}`);
andThen(() => {
assert.ok(findAll('.active-deployment').length === 1, 'Active deployment');
2017-09-19 14:47:10 +00:00
assert.equal(
$('.active-deployment > .boxed-section-head .badge')
.get(0)
.textContent.trim(),
2017-09-19 14:47:10 +00:00
deployment.id.split('-')[0],
'The active deployment is the most recent running deployment'
);
assert.equal(
$('.active-deployment > .boxed-section-head .submit-time')
.get(0)
.textContent.trim(),
2017-09-19 14:47:10 +00:00
moment(version.submitTime / 1000000).fromNow(),
'Time since the job was submitted is in the active deployment header'
);
assert.equal(
$('.deployment-metrics .label:contains("Canaries") + .value')
.get(0)
.textContent.trim(),
2017-09-19 14:47:10 +00:00
`${sum(taskGroupSummaries, 'placedCanaries')} / ${sum(
taskGroupSummaries,
'desiredCanaries'
)}`,
'Canaries, both places and desired, are in the metrics'
);
assert.equal(
$('.deployment-metrics .label:contains("Placed") + .value')
.get(0)
.textContent.trim(),
2017-09-19 14:47:10 +00:00
sum(taskGroupSummaries, 'placedAllocs'),
'Placed allocs aggregates across task groups'
);
assert.equal(
$('.deployment-metrics .label:contains("Desired") + .value')
.get(0)
.textContent.trim(),
2017-09-19 14:47:10 +00:00
sum(taskGroupSummaries, 'desiredTotal'),
'Desired allocs aggregates across task groups'
);
assert.equal(
$('.deployment-metrics .label:contains("Healthy") + .value')
.get(0)
.textContent.trim(),
2017-09-19 14:47:10 +00:00
sum(taskGroupSummaries, 'healthyAllocs'),
'Healthy allocs aggregates across task groups'
);
assert.equal(
$('.deployment-metrics .label:contains("Unhealthy") + .value')
.get(0)
.textContent.trim(),
2017-09-19 14:47:10 +00:00
sum(taskGroupSummaries, 'unhealthyAllocs'),
'Unhealthy allocs aggregates across task groups'
);
assert.equal(
$('.deployment-metrics .notification')
.get(0)
.textContent.trim(),
2017-09-19 14:47:10 +00:00
deployment.statusDescription,
'Status description is in the metrics block'
);
});
});
test('the active deployment section can be expanded to show task groups and allocations', function(
assert
) {
job = server.create('job', { activeDeployment: true });
visit(`/jobs/${job.id}`);
andThen(() => {
assert.ok(
$('.active-deployment .boxed-section-head:contains("Task Groups")').length === 0,
2017-09-19 14:47:10 +00:00
'Task groups not found'
);
assert.ok(
$('.active-deployment .boxed-section-head:contains("Allocations")').length === 0,
2017-09-19 14:47:10 +00:00
'Allocations not found'
);
});
andThen(() => {
click('.active-deployment-details-toggle');
});
2017-09-19 14:47:10 +00:00
andThen(() => {
assert.ok(
$('.active-deployment .boxed-section-head:contains("Task Groups")').length === 1,
2017-09-19 14:47:10 +00:00
'Task groups found'
);
assert.ok(
$('.active-deployment .boxed-section-head:contains("Allocations")').length === 1,
2017-09-19 14:47:10 +00:00
'Allocations found'
);
});
});
2017-09-29 00:05:41 +00:00
test('when the job is not found, an error message is shown, but the URL persists', function(
assert
) {
visit('/jobs/not-a-real-job');
andThen(() => {
assert.equal(
server.pretender.handledRequests.findBy('status', 404).url,
'/v1/job/not-a-real-job',
'A request to the non-existent job is made'
);
assert.equal(currentURL(), '/jobs/not-a-real-job', 'The URL persists');
assert.ok(find('.error-message'), 'Error message is shown');
assert.equal(
find('.error-message .title').textContent,
'Not Found',
'Error message is for 404'
);
});
});
2017-10-11 17:12:10 +00:00
test('when there are namespaces, the job detail page states the namespace for the job', function(
assert
) {
server.createList('namespace', 2);
job = server.create('job');
const namespace = server.db.namespaces.find(job.namespaceId);
visit(`/jobs/${job.id}`);
andThen(() => {
assert.ok(
findAll('.job-stats span')[2].textContent.includes(namespace.name),
'Namespace included in stats'
);
});
});