Skip to content

Commit

Permalink
Add handling for allocation-less exec URL (hashicorp#8856)
Browse files Browse the repository at this point in the history
This closes hashicorp#8769. This new-window-opening code is not possible
to properly exercise within Ember’s testing facilities 😞
  • Loading branch information
backspace authored and fredrikhgrelland committed Sep 28, 2020
1 parent a970784 commit 522edf5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ui/app/utils/generate-exec-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ export default function generateExecUrl(router, { job, taskGroup, task, allocati
const queryParams = router.currentRoute.queryParams;

if (task) {
const queryParamsOptions = {
...queryParams,
};

if (allocation) {
queryParamsOptions.allocation = get(allocation, 'shortId');
}

return router.urlFor(
'exec.task-group.task',
get(job, 'plainId'),
get(taskGroup, 'name'),
get(task, 'name'),
{
queryParams: {
allocation: get(allocation, 'shortId'),
...queryParams,
},
queryParams: queryParamsOptions,
}
);
} else if (taskGroup) {
Expand Down
12 changes: 12 additions & 0 deletions ui/tests/unit/utils/generate-exec-url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ module('Unit | Utility | generate-exec-url', function(hooks) {
);
});

test('it generates an exec task URL without an allocation', function(assert) {
generateExecUrl(this.router, {
job: { plainId: 'job-name' },
taskGroup: { name: 'task-group-name' },
task: { name: 'task-name' },
});

assert.ok(
this.urlForSpy.calledWith('exec.task-group.task', 'job-name', 'task-group-name', 'task-name')
);
});

test('it includes query parameters from the current route', function(assert) {
this.router.currentRoute.queryParams = {
namespace: 'a-namespace',
Expand Down

0 comments on commit 522edf5

Please sign in to comment.