2017-09-30 00:41:12 +00:00
|
|
|
import { click, find, findAll, currentURL, visit, fillIn } 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';
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | jobs list', {
|
|
|
|
beforeEach() {
|
|
|
|
// Required for placing allocations (a result of creating jobs)
|
|
|
|
server.create('node');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('visiting /jobs', function(assert) {
|
|
|
|
visit('/jobs');
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/jobs');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('/jobs should list the first page of jobs sorted by modify index', function(assert) {
|
|
|
|
const jobsCount = 11;
|
|
|
|
const pageSize = 10;
|
|
|
|
server.createList('job', jobsCount, { createAllocations: false });
|
|
|
|
|
|
|
|
visit('/jobs');
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const sortedJobs = server.db.jobs.sortBy('modifyIndex').reverse();
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(findAll('[data-test-job-row]').length, pageSize);
|
2017-09-19 14:47:10 +00:00
|
|
|
for (var jobNumber = 0; jobNumber < pageSize; jobNumber++) {
|
2018-01-05 20:59:36 +00:00
|
|
|
const jobRow = findAll('[data-test-job-row]')[jobNumber];
|
2017-09-19 14:47:10 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
jobRow.querySelector('[data-test-job-name]').textContent,
|
2017-09-19 14:47:10 +00:00
|
|
|
sortedJobs[jobNumber].name,
|
|
|
|
'Jobs are ordered'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each job row should contain information about the job', function(assert) {
|
|
|
|
server.createList('job', 2);
|
|
|
|
const job = server.db.jobs.sortBy('modifyIndex').reverse()[0];
|
|
|
|
const taskGroups = server.db.taskGroups.where({ jobId: job.id });
|
|
|
|
|
|
|
|
visit('/jobs');
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
const jobRow = find('[data-test-job-row]');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(jobRow.querySelector('[data-test-job-name]').textContent, job.name, 'Name');
|
2017-09-26 07:47:16 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
jobRow.querySelector('[data-test-job-name] a').getAttribute('href'),
|
|
|
|
`/ui/jobs/${job.id}`,
|
|
|
|
'Detail Link'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
jobRow.querySelector('[data-test-job-status]').textContent.trim(),
|
2017-09-26 07:47:16 +00:00
|
|
|
job.status,
|
|
|
|
'Status'
|
|
|
|
);
|
2018-01-26 23:01:10 +00:00
|
|
|
assert.equal(jobRow.querySelector('[data-test-job-type]').textContent, typeForJob(job), 'Type');
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(
|
|
|
|
jobRow.querySelector('[data-test-job-priority]').textContent,
|
|
|
|
job.priority,
|
|
|
|
'Priority'
|
|
|
|
);
|
2017-10-23 17:30:11 +00:00
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
jobRow.querySelector('[data-test-job-task-groups]').textContent.trim(),
|
2017-10-23 17:30:11 +00:00
|
|
|
taskGroups.length,
|
|
|
|
'# Groups'
|
|
|
|
);
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each job row should link to the corresponding job', function(assert) {
|
|
|
|
server.create('job');
|
|
|
|
const job = server.db.jobs[0];
|
|
|
|
|
|
|
|
visit('/jobs');
|
2017-09-26 07:47:16 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
click('[data-test-job-name] a');
|
2017-09-26 07:47:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}`);
|
|
|
|
});
|
|
|
|
});
|
2017-09-30 00:41:12 +00:00
|
|
|
|
|
|
|
test('when there are no jobs, there is an empty message', function(assert) {
|
|
|
|
visit('/jobs');
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(find('[data-test-empty-jobs-list]'));
|
|
|
|
assert.equal(find('[data-test-empty-jobs-list-headline]').textContent, 'No Jobs');
|
2017-09-30 00:41:12 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-26 23:01:10 +00:00
|
|
|
test('when there are jobs, but no matches for a search result, there is an empty message', function(assert) {
|
2017-09-30 00:41:12 +00:00
|
|
|
server.create('job', { name: 'cat 1' });
|
|
|
|
server.create('job', { name: 'cat 2' });
|
|
|
|
|
|
|
|
visit('/jobs');
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
fillIn('[data-test-jobs-search] input', 'dog');
|
2017-09-30 00:41:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(find('[data-test-empty-jobs-list]'));
|
|
|
|
assert.equal(find('[data-test-empty-jobs-list-headline]').textContent, 'No Matches');
|
2017-09-30 00:41:12 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2018-01-26 23:01:10 +00:00
|
|
|
test('when the namespace query param is set, only matching jobs are shown and the namespace value is forwarded to app state', function(assert) {
|
2017-10-11 20:44:27 +00:00
|
|
|
server.createList('namespace', 2);
|
|
|
|
const job1 = server.create('job', { namespaceId: server.db.namespaces[0].id });
|
|
|
|
const job2 = server.create('job', { namespaceId: server.db.namespaces[1].id });
|
|
|
|
|
|
|
|
visit('/jobs');
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(findAll('[data-test-job-row]').length, 1, 'One job in the default namespace');
|
|
|
|
assert.equal(find('[data-test-job-name]').textContent, job1.name, 'The correct job is shown');
|
2017-10-11 20:44:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const secondNamespace = server.db.namespaces[1];
|
|
|
|
visit(`/jobs?namespace=${secondNamespace.id}`);
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(
|
|
|
|
findAll('[data-test-job-row]').length,
|
|
|
|
1,
|
|
|
|
`One job in the ${secondNamespace.name} namespace`
|
|
|
|
);
|
|
|
|
assert.equal(find('[data-test-job-name]').textContent, job2.name, 'The correct job is shown');
|
2017-10-11 20:44:27 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-24 23:08:01 +00:00
|
|
|
|
2018-01-26 23:01:10 +00:00
|
|
|
test('when accessing jobs is forbidden, show a message with a link to the tokens page', function(assert) {
|
2017-10-24 23:08:01 +00:00
|
|
|
server.pretender.get('/v1/jobs', () => [403, {}, null]);
|
|
|
|
|
|
|
|
visit('/jobs');
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(find('[data-test-error-title]').textContent, 'Not Authorized');
|
2017-10-24 23:08:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
click('[data-test-error-message] a');
|
2017-10-24 23:08:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
|
|
});
|
|
|
|
});
|
2018-01-26 23:01:10 +00:00
|
|
|
|
|
|
|
function typeForJob(job) {
|
|
|
|
return job.periodic ? 'periodic' : job.parameterized ? 'parameterized' : job.type;
|
|
|
|
}
|