github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/unit/utils/generate-exec-url-test.js (about) 1 import generateExecUrl from 'nomad-ui/utils/generate-exec-url'; 2 import { module, test } from 'qunit'; 3 import sinon from 'sinon'; 4 5 const emptyOptions = { queryParams: {} }; 6 7 module('Unit | Utility | generate-exec-url', function(hooks) { 8 hooks.beforeEach(function() { 9 this.urlForSpy = sinon.spy(); 10 this.router = { urlFor: this.urlForSpy, currentRoute: { queryParams: {} } }; 11 }); 12 13 test('it generates an exec job URL', function(assert) { 14 generateExecUrl(this.router, { job: { plainId: 'job-name' } }); 15 16 assert.ok(this.urlForSpy.calledWith('exec', 'job-name', emptyOptions)); 17 }); 18 19 test('it generates an exec job URL with an allocation and task group when there are multiple tasks', function(assert) { 20 generateExecUrl(this.router, { 21 job: { plainId: 'job-name' }, 22 allocation: { 23 shortId: 'allocation-short-id', 24 taskGroup: { name: 'task-group-name', tasks: [0, 1, 2] }, 25 }, 26 }); 27 28 assert.ok( 29 this.urlForSpy.calledWith('exec.task-group', 'job-name', 'task-group-name', { 30 queryParams: { allocation: 'allocation-short-id' }, 31 }) 32 ); 33 }); 34 35 test('it generates an exec job URL with an allocation, task group, and task when there is only one task', function(assert) { 36 generateExecUrl(this.router, { 37 job: { plainId: 'job-name' }, 38 allocation: { 39 shortId: 'allocation-short-id', 40 taskGroup: { name: 'task-group-name', tasks: [{ name: 'task-name' }] }, 41 }, 42 }); 43 44 assert.ok( 45 this.urlForSpy.calledWith( 46 'exec.task-group.task', 47 'job-name', 48 'task-group-name', 49 'task-name', 50 { 51 queryParams: { allocation: 'allocation-short-id' }, 52 } 53 ) 54 ); 55 }); 56 57 test('it generates an exec task group URL', function(assert) { 58 generateExecUrl(this.router, { 59 job: { plainId: 'job-name' }, 60 taskGroup: { name: 'task-group-name' }, 61 }); 62 63 assert.ok( 64 this.urlForSpy.calledWith('exec.task-group', 'job-name', 'task-group-name', emptyOptions) 65 ); 66 }); 67 68 test('it generates an exec task URL', function(assert) { 69 generateExecUrl(this.router, { 70 allocation: { shortId: 'allocation-short-id' }, 71 job: { plainId: 'job-name' }, 72 taskGroup: { name: 'task-group-name' }, 73 task: { name: 'task-name' }, 74 }); 75 76 assert.ok( 77 this.urlForSpy.calledWith( 78 'exec.task-group.task', 79 'job-name', 80 'task-group-name', 81 'task-name', 82 { queryParams: { allocation: 'allocation-short-id' } } 83 ) 84 ); 85 }); 86 87 test('it generates an exec task URL without an allocation', function(assert) { 88 generateExecUrl(this.router, { 89 job: { plainId: 'job-name' }, 90 taskGroup: { name: 'task-group-name' }, 91 task: { name: 'task-name' }, 92 }); 93 94 assert.ok( 95 this.urlForSpy.calledWith('exec.task-group.task', 'job-name', 'task-group-name', 'task-name') 96 ); 97 }); 98 99 test('it includes job namespace and region when they exist', function(assert) { 100 generateExecUrl(this.router, { 101 job: { 102 namespace: { 103 name: 'a-namespace', 104 }, 105 plainId: 'job-name', 106 region: 'a-region', 107 }, 108 allocation: { shortId: 'id', taskGroup: { name: 'task-group-name', tasks: [0, 1] } }, 109 }); 110 111 assert.ok( 112 this.urlForSpy.calledWith('exec.task-group', 'job-name', 'task-group-name', { 113 queryParams: { allocation: 'id', namespace: 'a-namespace', region: 'a-region' }, 114 }) 115 ); 116 }); 117 });