2019-03-13 00:08:16 +00:00
|
|
|
import { currentURL } from '@ember/test-helpers';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2019-03-14 06:44:53 +00:00
|
|
|
import { selectChoose } from 'ember-power-select/test-support';
|
2019-09-26 18:47:07 +00:00
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
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-11-08 05:04:27 +00:00
|
|
|
moduleForJob('Acceptance | job detail (batch)', 'allocations', () =>
|
2019-04-12 03:08:43 +00:00
|
|
|
server.create('job', { type: 'batch', shallow: true })
|
2018-11-08 05:04:27 +00:00
|
|
|
);
|
|
|
|
moduleForJob('Acceptance | job detail (system)', 'allocations', () =>
|
2019-04-12 03:08:43 +00:00
|
|
|
server.create('job', { type: 'system', shallow: true })
|
2018-11-08 05:04:27 +00:00
|
|
|
);
|
|
|
|
moduleForJob('Acceptance | job detail (periodic)', 'children', () =>
|
2019-04-12 03:08:43 +00:00
|
|
|
server.create('job', 'periodic', { shallow: true })
|
2018-11-08 05:04:27 +00:00
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-11-08 05:04:27 +00:00
|
|
|
moduleForJob('Acceptance | job detail (parameterized)', 'children', () =>
|
2019-04-12 03:08:43 +00:00
|
|
|
server.create('job', 'parameterized', { shallow: true })
|
2018-02-02 01:22:09 +00:00
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-11-08 05:04:27 +00:00
|
|
|
moduleForJob('Acceptance | job detail (periodic child)', 'allocations', () => {
|
2019-04-12 03:08:43 +00:00
|
|
|
const parent = server.create('job', 'periodic', { childrenCount: 1, shallow: true });
|
2018-02-02 01:22:09 +00:00
|
|
|
return server.db.jobs.where({ parentId: parent.id })[0];
|
|
|
|
});
|
|
|
|
|
2018-11-08 05:04:27 +00:00
|
|
|
moduleForJob('Acceptance | job detail (parameterized child)', 'allocations', () => {
|
2019-04-12 03:08:43 +00:00
|
|
|
const parent = server.create('job', 'parameterized', { childrenCount: 1, shallow: true });
|
2018-02-02 01:22:09 +00:00
|
|
|
return server.db.jobs.where({ parentId: parent.id })[0];
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2018-11-08 05:04:27 +00:00
|
|
|
moduleForJob(
|
|
|
|
'Acceptance | job detail (service)',
|
|
|
|
'allocations',
|
|
|
|
() => server.create('job', { type: 'service' }),
|
|
|
|
{
|
2019-03-14 06:44:53 +00:00
|
|
|
'the subnav links to deployment': async (job, assert) => {
|
|
|
|
await JobDetail.tabFor('deployments').visit();
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}/deployments`);
|
|
|
|
},
|
|
|
|
'when the job is not found, an error message is shown, but the URL persists': async (
|
|
|
|
job,
|
|
|
|
assert
|
|
|
|
) => {
|
|
|
|
await JobDetail.visit({ id: 'not-a-real-job' });
|
|
|
|
|
|
|
|
assert.equal(
|
2020-01-20 20:57:01 +00:00
|
|
|
server.pretender.handledRequests
|
|
|
|
.filter(request => !request.url.includes('policy'))
|
|
|
|
.findBy('status', 404).url,
|
2019-03-14 06:44:53 +00:00
|
|
|
'/v1/job/not-a-real-job',
|
|
|
|
'A request to the nonexistent job is made'
|
|
|
|
);
|
|
|
|
assert.equal(currentURL(), '/jobs/not-a-real-job', 'The URL persists');
|
|
|
|
assert.ok(JobDetail.error.isPresent, 'Error message is shown');
|
|
|
|
assert.equal(JobDetail.error.title, 'Not Found', 'Error message is for 404');
|
2018-11-08 05:04:27 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Acceptance | job detail (with namespaces)', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-14 06:44:53 +00:00
|
|
|
setupMirage(hooks);
|
|
|
|
|
2020-05-11 19:43:17 +00:00
|
|
|
let job, clientToken;
|
2019-03-13 00:04:16 +00:00
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
2017-10-23 17:30:11 +00:00
|
|
|
server.createList('namespace', 2);
|
|
|
|
server.create('node');
|
2020-05-11 19:43:17 +00:00
|
|
|
job = server.create('job', { type: 'service', status: 'running', namespaceId: server.db.namespaces[1].name });
|
2017-10-23 23:59:30 +00:00
|
|
|
server.createList('job', 3, { namespaceId: server.db.namespaces[0].name });
|
2020-05-11 19:43:17 +00:00
|
|
|
|
|
|
|
server.create('token');
|
|
|
|
clientToken = server.create('token');
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-10-23 17:30:11 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when there are namespaces, the job detail page states the namespace for the job', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const namespace = server.db.namespaces.find(job.namespaceId);
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobDetail.visit({ id: job.id, namespace: namespace.name });
|
2017-10-11 17:12:10 +00:00
|
|
|
|
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
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when switching namespaces, the app redirects to /jobs with the new namespace', async function(assert) {
|
2019-03-13 00:04:16 +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;
|
2017-10-23 23:59:30 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobDetail.visit({ id: job.id, namespace: namespace.name });
|
2017-10-23 23:59:30 +00:00
|
|
|
|
2018-07-11 02:20:02 +00:00
|
|
|
// TODO: Migrate to Page Objects
|
2019-03-14 06:44:53 +00:00
|
|
|
await selectChoose('[data-test-namespace-switcher]', label);
|
2017-10-23 23:59:30 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|
2020-05-11 19:43:17 +00:00
|
|
|
|
|
|
|
test('the exec button state can change between namespaces', async function(assert) {
|
|
|
|
const job1 = server.create('job', { status: 'running', namespaceId: server.db.namespaces[0].id });
|
|
|
|
const job2 = server.create('job', { status: 'running', namespaceId: server.db.namespaces[1].id });
|
|
|
|
|
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
|
|
|
|
|
|
|
const policy = server.create('policy', {
|
|
|
|
id: 'something',
|
|
|
|
name: 'something',
|
|
|
|
rulesJSON: {
|
|
|
|
Namespaces: [
|
|
|
|
{
|
|
|
|
Name: job1.namespaceId,
|
|
|
|
Capabilities: ['list-jobs', 'alloc-exec'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: job2.namespaceId,
|
|
|
|
Capabilities: ['list-jobs'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
clientToken.policyIds = [policy.id];
|
|
|
|
clientToken.save();
|
|
|
|
|
|
|
|
await JobDetail.visit({ id: job1.id });
|
|
|
|
assert.notOk(JobDetail.execButton.isDisabled);
|
|
|
|
|
|
|
|
const secondNamespace = server.db.namespaces[1];
|
|
|
|
await JobDetail.visit({ id: job2.id, namespace: secondNamespace.name });
|
|
|
|
assert.ok(JobDetail.execButton.isDisabled);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the anonymous policy is fetched to check whether to show the exec button', async function(assert) {
|
|
|
|
window.localStorage.removeItem('nomadTokenSecret');
|
|
|
|
|
|
|
|
server.create('policy', {
|
|
|
|
id: 'anonymous',
|
|
|
|
name: 'anonymous',
|
|
|
|
rulesJSON: {
|
|
|
|
Namespaces: [
|
|
|
|
{
|
|
|
|
Name: 'default',
|
|
|
|
Capabilities: ['list-jobs', 'alloc-exec'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await JobDetail.visit({ id: job.id, namespace: server.db.namespaces[1].name });
|
|
|
|
assert.notOk(JobDetail.execButton.isDisabled);
|
|
|
|
});
|
2017-10-23 23:59:30 +00:00
|
|
|
});
|