2019-03-13 00:08:16 +00:00
|
|
|
|
import { currentURL } from '@ember/test-helpers';
|
2018-08-17 00:22:58 +00:00
|
|
|
|
import { assign } from '@ember/polyfills';
|
2019-03-13 00:04:16 +00:00
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2019-09-26 18:47:07 +00:00
|
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2020-07-28 17:59:14 +00:00
|
|
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
2019-03-14 06:44:53 +00:00
|
|
|
|
import setupCodeMirror from 'nomad-ui/tests/helpers/codemirror';
|
2018-08-17 00:22:58 +00:00
|
|
|
|
import JobRun from 'nomad-ui/tests/pages/jobs/run';
|
|
|
|
|
|
|
|
|
|
const newJobName = 'new-job';
|
2018-08-20 22:04:33 +00:00
|
|
|
|
const newJobTaskGroupName = 'redis';
|
2018-08-17 00:22:58 +00:00
|
|
|
|
|
2020-01-20 20:57:01 +00:00
|
|
|
|
let managementToken, clientToken;
|
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
const jsonJob = (overrides) => {
|
2018-08-17 00:22:58 +00:00
|
|
|
|
return JSON.stringify(
|
|
|
|
|
assign(
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
Name: newJobName,
|
|
|
|
|
Namespace: 'default',
|
|
|
|
|
Datacenters: ['dc1'],
|
|
|
|
|
Priority: 50,
|
2018-08-20 22:04:33 +00:00
|
|
|
|
TaskGroups: [
|
|
|
|
|
{
|
|
|
|
|
Name: newJobTaskGroupName,
|
|
|
|
|
Tasks: [
|
|
|
|
|
{
|
|
|
|
|
Name: 'redis',
|
2018-08-17 00:22:58 +00:00
|
|
|
|
Driver: 'docker',
|
|
|
|
|
},
|
2018-08-20 22:04:33 +00:00
|
|
|
|
],
|
2018-08-17 00:22:58 +00:00
|
|
|
|
},
|
2018-08-20 22:04:33 +00:00
|
|
|
|
],
|
2018-08-17 00:22:58 +00:00
|
|
|
|
},
|
|
|
|
|
overrides
|
|
|
|
|
),
|
|
|
|
|
null,
|
|
|
|
|
2
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
module('Acceptance | job run', function (hooks) {
|
2019-03-13 00:04:16 +00:00
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
|
setupMirage(hooks);
|
2019-03-14 06:44:53 +00:00
|
|
|
|
setupCodeMirror(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
hooks.beforeEach(function () {
|
2018-08-17 00:22:58 +00:00
|
|
|
|
// Required for placing allocations (a result of creating jobs)
|
|
|
|
|
server.create('node');
|
2020-01-20 20:57:01 +00:00
|
|
|
|
|
|
|
|
|
managementToken = server.create('token');
|
|
|
|
|
clientToken = server.create('token');
|
|
|
|
|
|
|
|
|
|
window.localStorage.nomadTokenSecret = managementToken.secretId;
|
2019-03-13 00:04:16 +00:00
|
|
|
|
});
|
2018-08-17 00:22:58 +00:00
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
|
assert.expect(1);
|
|
|
|
|
|
2020-07-28 17:59:14 +00:00
|
|
|
|
await JobRun.visit();
|
2020-08-25 15:56:02 +00:00
|
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
test('visiting /jobs/run', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
|
await JobRun.visit();
|
2018-08-17 00:22:58 +00:00
|
|
|
|
|
|
|
|
|
assert.equal(currentURL(), '/jobs/run');
|
2019-07-17 20:02:58 +00:00
|
|
|
|
assert.equal(document.title, 'Run a job - Nomad');
|
2018-08-17 00:22:58 +00:00
|
|
|
|
});
|
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
test('when submitting a job, the site redirects to the new job overview page', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
|
const spec = jsonJob();
|
2018-08-17 00:22:58 +00:00
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
|
await JobRun.visit();
|
2018-08-17 00:22:58 +00:00
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
|
await JobRun.editor.editor.fillIn(spec);
|
|
|
|
|
await JobRun.editor.plan();
|
|
|
|
|
await JobRun.editor.run();
|
2018-08-17 00:22:58 +00:00
|
|
|
|
assert.equal(
|
|
|
|
|
currentURL(),
|
|
|
|
|
`/jobs/${newJobName}`,
|
|
|
|
|
`Redirected to the job overview page for ${newJobName}`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
test('when submitting a job to a different namespace, the redirect to the job overview page takes namespace into account', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
|
const newNamespace = 'second-namespace';
|
2018-08-17 00:22:58 +00:00
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
|
server.create('namespace', { id: newNamespace });
|
|
|
|
|
const spec = jsonJob({ Namespace: newNamespace });
|
2018-08-17 00:22:58 +00:00
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
|
await JobRun.visit();
|
2018-08-17 00:22:58 +00:00
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
|
await JobRun.editor.editor.fillIn(spec);
|
|
|
|
|
await JobRun.editor.plan();
|
|
|
|
|
await JobRun.editor.run();
|
2018-08-17 00:22:58 +00:00
|
|
|
|
assert.equal(
|
|
|
|
|
currentURL(),
|
|
|
|
|
`/jobs/${newJobName}?namespace=${newNamespace}`,
|
|
|
|
|
`Redirected to the job overview page for ${newJobName} and switched the namespace to ${newNamespace}`
|
|
|
|
|
);
|
|
|
|
|
});
|
2020-01-20 20:57:01 +00:00
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
test('when the user doesn’t have permission to run a job, redirects to the job overview page', async function (assert) {
|
2020-01-20 20:57:01 +00:00
|
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
|
|
|
|
|
|
|
|
|
await JobRun.visit();
|
|
|
|
|
assert.equal(currentURL(), '/jobs');
|
|
|
|
|
});
|
2021-07-14 20:27:24 +00:00
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
test('when using client token user can still go to job page if they have correct permissions', async function (assert) {
|
2021-07-14 20:27:24 +00:00
|
|
|
|
const clientTokenWithPolicy = server.create('token');
|
|
|
|
|
const newNamespace = 'second-namespace';
|
|
|
|
|
|
|
|
|
|
server.create('namespace', { id: newNamespace });
|
|
|
|
|
server.create('job', {
|
|
|
|
|
groupCount: 0,
|
|
|
|
|
createAllocations: false,
|
|
|
|
|
shallow: true,
|
|
|
|
|
noActiveDeployment: true,
|
|
|
|
|
namespaceId: newNamespace,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const policy = server.create('policy', {
|
|
|
|
|
id: 'something',
|
|
|
|
|
name: 'something',
|
|
|
|
|
rulesJSON: {
|
|
|
|
|
Namespaces: [
|
|
|
|
|
{
|
|
|
|
|
Name: newNamespace,
|
|
|
|
|
Capabilities: ['scale-job', 'submit-job', 'read-job', 'list-jobs'],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
clientTokenWithPolicy.policyIds = [policy.id];
|
|
|
|
|
clientTokenWithPolicy.save();
|
|
|
|
|
window.localStorage.nomadTokenSecret = clientTokenWithPolicy.secretId;
|
|
|
|
|
|
|
|
|
|
await JobRun.visit({ namespace: newNamespace });
|
|
|
|
|
assert.equal(currentURL(), `/jobs/run?namespace=${newNamespace}`);
|
|
|
|
|
});
|
2018-08-17 00:22:58 +00:00
|
|
|
|
});
|