github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/acceptance/job-run-test.js (about) 1 import { currentURL } from '@ember/test-helpers'; 2 import { assign } from '@ember/polyfills'; 3 import { module, test } from 'qunit'; 4 import { setupApplicationTest } from 'ember-qunit'; 5 import { setupMirage } from 'ember-cli-mirage/test-support'; 6 import setupCodeMirror from 'nomad-ui/tests/helpers/codemirror'; 7 import JobRun from 'nomad-ui/tests/pages/jobs/run'; 8 9 const newJobName = 'new-job'; 10 const newJobTaskGroupName = 'redis'; 11 12 let managementToken, clientToken; 13 14 const jsonJob = overrides => { 15 return JSON.stringify( 16 assign( 17 {}, 18 { 19 Name: newJobName, 20 Namespace: 'default', 21 Datacenters: ['dc1'], 22 Priority: 50, 23 TaskGroups: [ 24 { 25 Name: newJobTaskGroupName, 26 Tasks: [ 27 { 28 Name: 'redis', 29 Driver: 'docker', 30 }, 31 ], 32 }, 33 ], 34 }, 35 overrides 36 ), 37 null, 38 2 39 ); 40 }; 41 42 module('Acceptance | job run', function(hooks) { 43 setupApplicationTest(hooks); 44 setupMirage(hooks); 45 setupCodeMirror(hooks); 46 47 hooks.beforeEach(function() { 48 // Required for placing allocations (a result of creating jobs) 49 server.create('node'); 50 51 managementToken = server.create('token'); 52 clientToken = server.create('token'); 53 54 window.localStorage.nomadTokenSecret = managementToken.secretId; 55 }); 56 57 test('visiting /jobs/run', async function(assert) { 58 await JobRun.visit(); 59 60 assert.equal(currentURL(), '/jobs/run'); 61 assert.equal(document.title, 'Run a job - Nomad'); 62 }); 63 64 test('when submitting a job, the site redirects to the new job overview page', async function(assert) { 65 const spec = jsonJob(); 66 67 await JobRun.visit(); 68 69 await JobRun.editor.editor.fillIn(spec); 70 await JobRun.editor.plan(); 71 await JobRun.editor.run(); 72 assert.equal( 73 currentURL(), 74 `/jobs/${newJobName}`, 75 `Redirected to the job overview page for ${newJobName}` 76 ); 77 }); 78 79 test('when submitting a job to a different namespace, the redirect to the job overview page takes namespace into account', async function(assert) { 80 const newNamespace = 'second-namespace'; 81 82 server.create('namespace', { id: newNamespace }); 83 const spec = jsonJob({ Namespace: newNamespace }); 84 85 await JobRun.visit(); 86 87 await JobRun.editor.editor.fillIn(spec); 88 await JobRun.editor.plan(); 89 await JobRun.editor.run(); 90 assert.equal( 91 currentURL(), 92 `/jobs/${newJobName}?namespace=${newNamespace}`, 93 `Redirected to the job overview page for ${newJobName} and switched the namespace to ${newNamespace}` 94 ); 95 }); 96 97 test('when the user doesn’t have permission to run a job, redirects to the job overview page', async function(assert) { 98 window.localStorage.nomadTokenSecret = clientToken.secretId; 99 100 await JobRun.visit(); 101 assert.equal(currentURL(), '/jobs'); 102 }); 103 });