2018-07-11 02:33:22 +00:00
|
|
|
import { currentURL } from 'ember-native-dom-helpers';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { test } from 'qunit';
|
|
|
|
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
|
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;
|
|
|
|
|
2017-09-26 07:47:16 +00:00
|
|
|
moduleForAcceptance('Acceptance | job definition', {
|
2017-09-19 14:47:10 +00:00
|
|
|
beforeEach() {
|
|
|
|
server.create('node');
|
|
|
|
server.create('job');
|
|
|
|
job = server.db.jobs[0];
|
2018-07-11 02:33:22 +00:00
|
|
|
Definition.visit({ id: job.id });
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('visiting /jobs/:job_id/definition', function(assert) {
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}/definition`);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the job definition page contains a json viewer component', function(assert) {
|
2018-07-11 02:33:22 +00:00
|
|
|
assert.ok(Definition.jsonViewer, 'JSON viewer found');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('the job definition page requests the job to display in an unmutated form', function(assert) {
|
|
|
|
const jobURL = `/v1/job/${job.id}`;
|
2017-10-23 17:30:11 +00:00
|
|
|
const jobRequests = server.pretender.handledRequests
|
|
|
|
.map(req => req.url.split('?')[0])
|
|
|
|
.filter(url => url === jobURL);
|
2017-09-19 14:47:10 +00:00
|
|
|
assert.ok(jobRequests.length === 2, 'Two requests for the job were made');
|
|
|
|
});
|
2018-08-23 17:26:20 +00:00
|
|
|
|
|
|
|
test('the job definition can be edited', function(assert) {
|
|
|
|
assert.notOk(Definition.editor.isPresent, 'Editor is not shown on load');
|
|
|
|
|
|
|
|
Definition.edit();
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.ok(Definition.editor.isPresent, 'Editor is shown after clicking edit');
|
|
|
|
assert.notOk(Definition.jsonViewer, 'Editor replaces the JSON viewer');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when in editing mode, the action can be canceled, showing the read-only definition again', function(assert) {
|
|
|
|
Definition.edit();
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
Definition.editor.cancelEditing();
|
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.ok(Definition.jsonViewer, 'The JSON Viewer is back');
|
|
|
|
assert.notOk(Definition.editor.isPresent, 'The editor is gone');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when in editing mode, the editor is prepopulated with the job definition', function(assert) {
|
|
|
|
const requests = server.pretender.handledRequests;
|
|
|
|
const jobDefinition = requests.findBy('url', `/v1/job/${job.id}`).responseText;
|
|
|
|
const formattedJobDefinition = JSON.stringify(JSON.parse(jobDefinition), null, 2);
|
|
|
|
|
|
|
|
Definition.edit();
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
Definition.editor.editor.contents,
|
|
|
|
formattedJobDefinition,
|
|
|
|
'The editor already has the job definition in it'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when changes are submitted, the site redirects to the job overview page', function(assert) {
|
|
|
|
Definition.edit();
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
Definition.editor.plan();
|
|
|
|
Definition.editor.run();
|
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), `/jobs/${job.id}`, 'Now on the job overview page');
|
|
|
|
});
|
|
|
|
});
|