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;
|
|
|
|
|
|
2018-08-17 00:22:58 +00:00
|
|
|
|
const jsonJob = overrides => {
|
|
|
|
|
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
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
|
module('Acceptance | job run', function(hooks) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-07-28 17:59:14 +00:00
|
|
|
|
test('it passes an accessibility audit', async function(assert) {
|
|
|
|
|
await JobRun.visit();
|
|
|
|
|
await a11yAudit();
|
|
|
|
|
assert.ok(true, 'a11y audit passes');
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
|
test('visiting /jobs/run', async function(assert) {
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
2019-03-14 06:44:53 +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}`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-14 06:44:53 +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
|
|
|
|
|
|
|
|
|
test('when the user doesn’t have permission to run a job, redirects to the job overview page', async function(assert) {
|
|
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
|
|
|
|
|
|
|
|
|
await JobRun.visit();
|
|
|
|
|
assert.equal(currentURL(), '/jobs');
|
|
|
|
|
});
|
2018-08-17 00:22:58 +00:00
|
|
|
|
});
|