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