From 1f593bce10c6ce33c2613d0f5d2daa48233a8635 Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Wed, 9 Sep 2020 11:03:43 -0500 Subject: [PATCH] Add handling for allocation-less exec URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This closes #8769. This new-window-opening code is not possible to properly exercise within Ember’s testing facilities 😞 --- ui/app/utils/generate-exec-url.js | 13 +++++++++---- ui/tests/unit/utils/generate-exec-url-test.js | 12 ++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ui/app/utils/generate-exec-url.js b/ui/app/utils/generate-exec-url.js index c8621896be54..f4740d15d881 100644 --- a/ui/app/utils/generate-exec-url.js +++ b/ui/app/utils/generate-exec-url.js @@ -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) { diff --git a/ui/tests/unit/utils/generate-exec-url-test.js b/ui/tests/unit/utils/generate-exec-url-test.js index 958508edc5ad..6be39412ddd9 100644 --- a/ui/tests/unit/utils/generate-exec-url-test.js +++ b/ui/tests/unit/utils/generate-exec-url-test.js @@ -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',