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