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-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-07-11 02:33:22 +00:00
|
|
|
import Definition from 'nomad-ui/tests/pages/jobs/job/definition';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
let job;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | job definition', 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(async function () {
|
2017-09-19 14:47:10 +00:00
|
|
|
server.create('node');
|
|
|
|
server.create('job');
|
|
|
|
job = server.db.jobs[0];
|
2019-03-14 06:44:53 +00:00
|
|
|
await Definition.visit({ id: job.id });
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +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-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert, 'scrollable-region-focusable');
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('visiting /jobs/:job_id/definition', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}/definition`);
|
2019-07-17 20:02:58 +00:00
|
|
|
assert.equal(document.title, `Job ${job.name} definition - Nomad`);
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the job definition page contains a json viewer component', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.ok(Definition.jsonViewer, 'JSON viewer found');
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the job definition page requests the job to display in an unmutated form', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const jobURL = `/v1/job/${job.id}`;
|
|
|
|
const jobRequests = server.pretender.handledRequests
|
2021-12-28 14:45:20 +00:00
|
|
|
.map((req) => req.url.split('?')[0])
|
|
|
|
.filter((url) => url === jobURL);
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
jobRequests.length,
|
|
|
|
2,
|
|
|
|
'Two requests for the job were made'
|
|
|
|
);
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2018-08-23 17:26:20 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the job definition can be edited', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.notOk(Definition.editor.isPresent, 'Editor is not shown on load');
|
2018-08-23 17:26:20 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Definition.edit();
|
2018-08-23 17:26:20 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.ok(
|
|
|
|
Definition.editor.isPresent,
|
|
|
|
'Editor is shown after clicking edit'
|
|
|
|
);
|
2018-08-23 17:26:20 +00:00
|
|
|
assert.notOk(Definition.jsonViewer, 'Editor replaces the JSON viewer');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when in editing mode, the action can be canceled, showing the read-only definition again', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await Definition.edit();
|
2018-08-23 17:26:20 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Definition.editor.cancelEditing();
|
2018-08-23 17:26:20 +00:00
|
|
|
assert.ok(Definition.jsonViewer, 'The JSON Viewer is back');
|
|
|
|
assert.notOk(Definition.editor.isPresent, 'The editor is gone');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when in editing mode, the editor is prepopulated with the job definition', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const requests = server.pretender.handledRequests;
|
2021-12-28 16:08:12 +00:00
|
|
|
const jobDefinition = requests.findBy(
|
|
|
|
'url',
|
|
|
|
`/v1/job/${job.id}`
|
|
|
|
).responseText;
|
|
|
|
const formattedJobDefinition = JSON.stringify(
|
|
|
|
JSON.parse(jobDefinition),
|
|
|
|
null,
|
|
|
|
2
|
|
|
|
);
|
2018-08-23 17:26:20 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Definition.edit();
|
2018-08-23 17:26:20 +00:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
Definition.editor.editor.contents,
|
|
|
|
formattedJobDefinition,
|
|
|
|
'The editor already has the job definition in it'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when changes are submitted, the site redirects to the job overview page', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await Definition.edit();
|
2018-08-23 17:26:20 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Definition.editor.plan();
|
|
|
|
await Definition.editor.run();
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/jobs/${job.id}`,
|
|
|
|
'Now on the job overview page'
|
|
|
|
);
|
2018-08-23 17:26:20 +00:00
|
|
|
});
|
2018-11-05 23:20:31 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the job for the definition is not found, an error message is shown, but the URL persists', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await Definition.visit({ id: 'not-a-real-job' });
|
2018-11-05 23:20:31 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2020-01-20 20:57:01 +00:00
|
|
|
server.pretender.handledRequests
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((request) => !request.url.includes('policy'))
|
2020-01-20 20:57:01 +00:00
|
|
|
.findBy('status', 404).url,
|
2018-11-05 23:20:31 +00:00
|
|
|
'/v1/job/not-a-real-job',
|
|
|
|
'A request to the nonexistent job is made'
|
|
|
|
);
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
'/jobs/not-a-real-job/definition',
|
|
|
|
'The URL persists'
|
|
|
|
);
|
2018-11-05 23:20:31 +00:00
|
|
|
assert.ok(Definition.error.isPresent, 'Error message is shown');
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
Definition.error.title,
|
|
|
|
'Not Found',
|
|
|
|
'Error message is for 404'
|
|
|
|
);
|
2018-11-05 23:20:31 +00:00
|
|
|
});
|
|
|
|
});
|