2018-08-17 00:22:58 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
|
|
|
import { currentURL } from 'ember-native-dom-helpers';
|
|
|
|
import { test } from 'qunit';
|
|
|
|
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | job run', {
|
|
|
|
beforeEach() {
|
|
|
|
// Required for placing allocations (a result of creating jobs)
|
|
|
|
server.create('node');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('visiting /jobs/run', function(assert) {
|
|
|
|
JobRun.visit();
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/jobs/run');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-23 16:00:47 +00:00
|
|
|
test('when submitting a job, the site redirects to the new job overview page', function(assert) {
|
2018-08-17 00:22:58 +00:00
|
|
|
const spec = jsonJob();
|
|
|
|
|
|
|
|
JobRun.visit();
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-08-23 16:00:47 +00:00
|
|
|
JobRun.editor.editor.fillIn(spec);
|
|
|
|
JobRun.editor.plan();
|
2018-08-17 00:22:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-08-23 16:00:47 +00:00
|
|
|
JobRun.editor.run();
|
2018-08-17 00:22:58 +00:00
|
|
|
});
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/jobs/${newJobName}`,
|
|
|
|
`Redirected to the job overview page for ${newJobName}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when submitting a job to a different namespace, the redirect to the job overview page takes namespace into account', function(assert) {
|
|
|
|
const newNamespace = 'second-namespace';
|
|
|
|
|
|
|
|
server.create('namespace', { id: newNamespace });
|
|
|
|
const spec = jsonJob({ Namespace: newNamespace });
|
|
|
|
|
|
|
|
JobRun.visit();
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-08-23 16:00:47 +00:00
|
|
|
JobRun.editor.editor.fillIn(spec);
|
|
|
|
JobRun.editor.plan();
|
2018-08-17 00:22:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-08-23 16:00:47 +00:00
|
|
|
JobRun.editor.run();
|
2018-08-17 00:22:58 +00:00
|
|
|
});
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/jobs/${newJobName}?namespace=${newNamespace}`,
|
|
|
|
`Redirected to the job overview page for ${newJobName} and switched the namespace to ${newNamespace}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|