open-nomad/ui/tests/acceptance/job-run-test.js

89 lines
2.3 KiB
JavaScript
Raw Normal View History

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-03-13 01:09:19 +00:00
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
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';
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,
TaskGroups: [
{
Name: newJobTaskGroupName,
Tasks: [
{
Name: 'redis',
2018-08-17 00:22:58 +00:00
Driver: 'docker',
},
],
2018-08-17 00:22:58 +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);
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');
2019-03-13 00:04:16 +00:00
});
2018-08-17 00:22:58 +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');
});
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
await JobRun.visit();
2018-08-17 00:22:58 +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}`
);
});
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
await JobRun.visit();
2018-08-17 00:22:58 +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}`
);
});
});