2018-07-11 02:20:02 +00:00
|
|
|
import { currentURL, visit } from 'ember-native-dom-helpers';
|
2018-02-02 17:49:18 +00:00
|
|
|
import { test } from 'qunit';
|
2017-09-19 14:47:10 +00:00
|
|
|
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
|
2018-02-02 01:22:09 +00:00
|
|
|
import moduleForJob from 'nomad-ui/tests/helpers/module-for-job';
|
2018-07-11 02:20:02 +00:00
|
|
|
import JobDetail from 'nomad-ui/tests/pages/jobs/detail';
|
|
|
|
import JobsList from 'nomad-ui/tests/pages/jobs/list';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-02-02 01:22:09 +00:00
|
|
|
moduleForJob('Acceptance | job detail (batch)', () => server.create('job', { type: 'batch' }));
|
|
|
|
moduleForJob('Acceptance | job detail (system)', () => server.create('job', { type: 'system' }));
|
|
|
|
moduleForJob('Acceptance | job detail (periodic)', () => server.create('job', 'periodic'));
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-02-02 01:22:09 +00:00
|
|
|
moduleForJob('Acceptance | job detail (parameterized)', () =>
|
|
|
|
server.create('job', 'parameterized')
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-02-02 01:22:09 +00:00
|
|
|
moduleForJob('Acceptance | job detail (periodic child)', () => {
|
|
|
|
const parent = server.create('job', 'periodic');
|
|
|
|
return server.db.jobs.where({ parentId: parent.id })[0];
|
|
|
|
});
|
|
|
|
|
|
|
|
moduleForJob('Acceptance | job detail (parameterized child)', () => {
|
|
|
|
const parent = server.create('job', 'parameterized');
|
|
|
|
return server.db.jobs.where({ parentId: parent.id })[0];
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2018-02-02 01:22:09 +00:00
|
|
|
moduleForJob('Acceptance | job detail (service)', () => server.create('job', { type: 'service' }), {
|
|
|
|
'the subnav links to deployment': (job, assert) => {
|
2018-07-11 02:20:02 +00:00
|
|
|
JobDetail.tabFor('deployments').visit();
|
2018-02-02 01:22:09 +00:00
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}/deployments`);
|
|
|
|
});
|
|
|
|
},
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2018-02-02 01:22:09 +00:00
|
|
|
let job;
|
|
|
|
|
2018-02-02 17:49:18 +00:00
|
|
|
test('when the job is not found, an error message is shown, but the URL persists', function(assert) {
|
2017-09-29 00:05:41 +00:00
|
|
|
visit('/jobs/not-a-real-job');
|
2018-07-11 02:20:02 +00:00
|
|
|
JobDetail.visit({ id: 'not-a-real-job' });
|
2017-09-29 00:05:41 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
server.pretender.handledRequests.findBy('status', 404).url,
|
|
|
|
'/v1/job/not-a-real-job',
|
2018-03-12 18:26:37 +00:00
|
|
|
'A request to the nonexistent job is made'
|
2017-09-29 00:05:41 +00:00
|
|
|
);
|
|
|
|
assert.equal(currentURL(), '/jobs/not-a-real-job', 'The URL persists');
|
2018-07-11 02:20:02 +00:00
|
|
|
assert.ok(JobDetail.error.isPresent, 'Error message is shown');
|
|
|
|
assert.equal(JobDetail.error.title, 'Not Found', 'Error message is for 404');
|
2017-09-29 00:05:41 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2017-10-23 17:30:11 +00:00
|
|
|
moduleForAcceptance('Acceptance | job detail (with namespaces)', {
|
|
|
|
beforeEach() {
|
|
|
|
server.createList('namespace', 2);
|
|
|
|
server.create('node');
|
2018-02-02 17:49:18 +00:00
|
|
|
job = server.create('job', { type: 'service', namespaceId: server.db.namespaces[1].name });
|
2017-10-23 23:59:30 +00:00
|
|
|
server.createList('job', 3, { namespaceId: server.db.namespaces[0].name });
|
2017-10-23 17:30:11 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-02-02 17:49:18 +00:00
|
|
|
test('when there are namespaces, the job detail page states the namespace for the job', function(assert) {
|
2017-10-11 17:12:10 +00:00
|
|
|
const namespace = server.db.namespaces.find(job.namespaceId);
|
2018-07-11 02:20:02 +00:00
|
|
|
JobDetail.visit({ id: job.id, namespace: namespace.name });
|
2017-10-11 17:12:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 02:20:02 +00:00
|
|
|
assert.ok(JobDetail.statFor('namespace').text, 'Namespace included in stats');
|
2017-10-11 17:12:10 +00:00
|
|
|
});
|
|
|
|
});
|
2017-10-23 23:59:30 +00:00
|
|
|
|
2018-02-02 17:49:18 +00:00
|
|
|
test('when switching namespaces, the app redirects to /jobs with the new namespace', function(assert) {
|
2017-10-23 23:59:30 +00:00
|
|
|
const namespace = server.db.namespaces.find(job.namespaceId);
|
|
|
|
const otherNamespace = server.db.namespaces.toArray().find(ns => ns !== namespace).name;
|
|
|
|
const label = otherNamespace === 'default' ? 'Default Namespace' : otherNamespace;
|
|
|
|
|
2018-07-11 02:20:02 +00:00
|
|
|
JobDetail.visit({ id: job.id, namespace: namespace.name });
|
2017-10-23 23:59:30 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 02:20:02 +00:00
|
|
|
// TODO: Migrate to Page Objects
|
2018-01-05 20:59:36 +00:00
|
|
|
selectChoose('[data-test-namespace-switcher]', label);
|
2017-10-23 23:59:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL().split('?')[0], '/jobs', 'Navigated to /jobs');
|
2018-07-11 02:20:02 +00:00
|
|
|
|
2017-10-23 23:59:30 +00:00
|
|
|
const jobs = server.db.jobs
|
|
|
|
.where({ namespace: otherNamespace })
|
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse();
|
2018-07-11 02:20:02 +00:00
|
|
|
|
|
|
|
assert.equal(JobsList.jobs.length, jobs.length, 'Shows the right number of jobs');
|
|
|
|
JobsList.jobs.forEach((jobRow, index) => {
|
|
|
|
assert.equal(jobRow.name, jobs[index].name, `Job ${index} is right`);
|
2017-10-23 23:59:30 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|