2020-03-24 23:22:16 +00:00
|
|
|
import generateExecUrl from 'nomad-ui/utils/generate-exec-url';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
|
|
|
|
const emptyOptions = { queryParams: {} };
|
|
|
|
|
|
|
|
module('Unit | Utility | generate-exec-url', function(hooks) {
|
|
|
|
hooks.beforeEach(function() {
|
|
|
|
this.urlForSpy = sinon.spy();
|
|
|
|
this.router = { urlFor: this.urlForSpy, currentRoute: { queryParams: {} } };
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it generates an exec job URL', function(assert) {
|
2020-04-29 12:54:04 +00:00
|
|
|
generateExecUrl(this.router, { job: { plainId: 'job-name' } });
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
assert.ok(this.urlForSpy.calledWith('exec', 'job-name', emptyOptions));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it generates an exec job URL with an allocation', function(assert) {
|
2020-04-29 12:54:04 +00:00
|
|
|
generateExecUrl(this.router, { job: { plainId: 'job-name' }, allocation: { shortId: 'allocation-short-id' } });
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
this.urlForSpy.calledWith('exec', 'job-name', {
|
|
|
|
queryParams: { allocation: 'allocation-short-id' },
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it generates an exec task group URL', function(assert) {
|
2020-04-29 12:54:04 +00:00
|
|
|
generateExecUrl(this.router, { job: { plainId: 'job-name' }, taskGroup: { name: 'task-group-name' } });
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
this.urlForSpy.calledWith('exec.task-group', 'job-name', 'task-group-name', emptyOptions)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it generates an exec task URL', function(assert) {
|
|
|
|
generateExecUrl(this.router, {
|
2020-04-29 12:54:04 +00:00
|
|
|
allocation: { shortId: 'allocation-short-id' },
|
|
|
|
job: { plainId: 'job-name' },
|
|
|
|
taskGroup: { name: 'task-group-name' },
|
|
|
|
task: { name: 'task-name' },
|
2020-03-24 23:22:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
this.urlForSpy.calledWith(
|
|
|
|
'exec.task-group.task',
|
|
|
|
'job-name',
|
|
|
|
'task-group-name',
|
|
|
|
'task-name',
|
|
|
|
{ queryParams: { allocation: 'allocation-short-id' } }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it includes query parameters from the current route', function(assert) {
|
|
|
|
this.router.currentRoute.queryParams = {
|
|
|
|
namespace: 'a-namespace',
|
|
|
|
region: 'a-region',
|
|
|
|
};
|
|
|
|
|
2020-04-29 12:54:04 +00:00
|
|
|
generateExecUrl(this.router, { job: { plainId: 'job-name' }, allocation: { shortId: 'id' } });
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
this.urlForSpy.calledWith('exec', 'job-name', {
|
|
|
|
queryParams: { allocation: 'id', namespace: 'a-namespace', region: 'a-region' },
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|