2018-07-11 19:35:39 +00:00
|
|
|
import { currentURL } 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';
|
2018-07-11 01:42:19 +00:00
|
|
|
import JobsList from 'nomad-ui/tests/pages/jobs/list';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | jobs list', {
|
|
|
|
beforeEach() {
|
|
|
|
// Required for placing allocations (a result of creating jobs)
|
|
|
|
server.create('node');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('visiting /jobs', function(assert) {
|
2018-07-11 19:35:39 +00:00
|
|
|
JobsList.visit();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/jobs');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('/jobs should list the first page of jobs sorted by modify index', function(assert) {
|
2018-07-11 01:42:19 +00:00
|
|
|
const jobsCount = JobsList.pageSize + 1;
|
2017-09-19 14:47:10 +00:00
|
|
|
server.createList('job', jobsCount, { createAllocations: false });
|
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.visit();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const sortedJobs = server.db.jobs.sortBy('modifyIndex').reverse();
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(JobsList.jobs.length, JobsList.pageSize);
|
|
|
|
JobsList.jobs.forEach((job, index) => {
|
|
|
|
assert.equal(job.name, sortedJobs[index].name, 'Jobs are ordered');
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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 });
|
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.visit();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
const jobRow = JobsList.jobs.objectAt(0);
|
|
|
|
|
|
|
|
assert.equal(jobRow.name, job.name, 'Name');
|
|
|
|
assert.equal(jobRow.link, `/ui/jobs/${job.id}`, 'Detail Link');
|
|
|
|
assert.equal(jobRow.status, job.status, 'Status');
|
|
|
|
assert.equal(jobRow.type, typeForJob(job), 'Type');
|
|
|
|
assert.equal(jobRow.priority, job.priority, 'Priority');
|
2017-10-23 17:30:11 +00:00
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(jobRow.taskGroups, taskGroups.length, '# Groups');
|
2017-10-23 17:30:11 +00:00
|
|
|
});
|
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];
|
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.visit();
|
2017-09-26 07:47:16 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.jobs.objectAt(0).clickName();
|
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
|
|
|
|
2018-08-16 00:12:18 +00:00
|
|
|
test('the new job button transitions to the new job page', function(assert) {
|
|
|
|
JobsList.visit();
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
JobsList.runJob();
|
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/jobs/run');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-30 00:41:12 +00:00
|
|
|
test('when there are no jobs, there is an empty message', function(assert) {
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.visit();
|
2017-09-30 00:41:12 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.ok(JobsList.isEmpty, 'There is an empty message');
|
|
|
|
assert.equal(JobsList.emptyState.headline, 'No Jobs', 'The message is appropriate');
|
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' });
|
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.visit();
|
2017-09-30 00:41:12 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.search('dog');
|
2017-09-30 00:41:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.ok(JobsList.isEmpty, 'The empty message is shown');
|
|
|
|
assert.equal(JobsList.emptyState.headline, 'No Matches', 'The message is appropriate');
|
2017-09-30 00:41:12 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2018-10-30 21:17:23 +00:00
|
|
|
test('searching resets the current page', function(assert) {
|
|
|
|
server.createList('job', JobsList.pageSize + 1, { createAllocations: false });
|
|
|
|
JobsList.visit();
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
JobsList.nextPage();
|
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/jobs?page=2', 'Page query param captures page=2');
|
|
|
|
JobsList.search('foobar');
|
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/jobs?search=foobar', 'No page query param');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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 });
|
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.visit();
|
2017-10-11 20:44:27 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(JobsList.jobs.length, 1, 'One job in the default namespace');
|
|
|
|
assert.equal(JobsList.jobs.objectAt(0).name, job1.name, 'The correct job is shown');
|
2017-10-11 20:44:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const secondNamespace = server.db.namespaces[1];
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.visit({ namespace: secondNamespace.id });
|
2017-10-11 20:44:27 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(JobsList.jobs.length, 1, `One job in the ${secondNamespace.name} namespace`);
|
|
|
|
assert.equal(JobsList.jobs.objectAt(0).name, 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]);
|
|
|
|
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.visit();
|
2017-10-24 23:08:01 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
assert.equal(JobsList.error.title, 'Not Authorized');
|
2017-10-24 23:08:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 01:42:19 +00:00
|
|
|
JobsList.error.seekHelp();
|
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;
|
|
|
|
}
|