From 5c1e94c45330cdef72fe4f92b153565448701860 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Wed, 17 Oct 2018 12:55:00 -0700 Subject: [PATCH] Test coverage for breadcrumb qp change --- ui/app/routes/allocations/allocation.js | 12 +++-- ui/app/routes/jobs/job/task-group.js | 1 + ui/app/services/system.js | 2 +- ui/tests/acceptance/task-detail-test.js | 67 +++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 6 deletions(-) diff --git a/ui/app/routes/allocations/allocation.js b/ui/app/routes/allocations/allocation.js index 9a6c17b6424..1b0434fd5e0 100644 --- a/ui/app/routes/allocations/allocation.js +++ b/ui/app/routes/allocations/allocation.js @@ -14,18 +14,20 @@ export default Route.extend(WithWatchers, { // Allocation breadcrumbs extend from job / task group breadcrumbs // even though the route structure does not. breadcrumbs(model) { + const jobQueryParams = qpBuilder({ + jobNamespace: model.get('job.namespace.name') || 'default', + }); + return [ - { label: 'Jobs', args: ['jobs.index'] }, + { label: 'Jobs', args: ['jobs.index', jobQueryParams] }, ...jobCrumbs(model.get('job')), { label: model.get('taskGroupName'), args: [ 'jobs.job.task-group', - model.get('job'), + model.get('job.name'), model.get('taskGroupName'), - qpBuilder({ - jobNamespace: model.get('job.namespace.name') || 'default', - }), + jobQueryParams, ], }, { diff --git a/ui/app/routes/jobs/job/task-group.js b/ui/app/routes/jobs/job/task-group.js index a219f252f75..da17981c5d9 100644 --- a/ui/app/routes/jobs/job/task-group.js +++ b/ui/app/routes/jobs/job/task-group.js @@ -12,6 +12,7 @@ export default Route.extend(WithWatchers, { label: model.get('name'), args: [ 'jobs.job.task-group', + model.get('job'), model.get('name'), qpBuilder({ jobNamespace: model.get('job.namespace.name') || 'default' }), ], diff --git a/ui/app/services/system.js b/ui/app/services/system.js index 7d6d2179243..8acc729ddfd 100644 --- a/ui/app/services/system.js +++ b/ui/app/services/system.js @@ -113,7 +113,7 @@ export default Service.extend({ // If the namespace in localStorage is no longer in the cluster, it needs to // be cleared from localStorage - this.set('activeNamespace', null); + window.localStorage.removeItem('nomadActiveNamespace'); return this.get('namespaces').findBy('id', 'default'); }, set(key, value) { diff --git a/ui/tests/acceptance/task-detail-test.js b/ui/tests/acceptance/task-detail-test.js index 7d7df686df4..2f3b34480fb 100644 --- a/ui/tests/acceptance/task-detail-test.js +++ b/ui/tests/acceptance/task-detail-test.js @@ -204,3 +204,70 @@ moduleForAcceptance('Acceptance | task detail (no addresses)', { test('when the task has no addresses, the addresses table is not shown', function(assert) { assert.notOk(Task.hasAddresses, 'No addresses table'); }); + +moduleForAcceptance('Acceptance | task detail (different namespace)', { + beforeEach() { + server.create('agent'); + server.create('node'); + server.create('namespace'); + server.create('namespace', { id: 'other-namespace' }); + server.create('job', { createAllocations: false, namespaceId: 'other-namespace' }); + allocation = server.create('allocation', 'withTaskWithPorts'); + task = server.db.taskStates.where({ allocationId: allocation.id })[0]; + + Task.visit({ id: allocation.id, name: task.name }); + }, +}); + +test('breadcrumbs match jobs / job / task group / allocation / task', function(assert) { + const { jobId, taskGroup } = allocation; + const job = server.db.jobs.find(jobId); + + Task.breadcrumbFor('jobs.index').visit(); + andThen(() => { + assert.equal( + currentURL(), + '/jobs?namespace=other-namespace', + 'Jobs breadcrumb links correctly' + ); + }); + andThen(() => { + Task.visit({ id: allocation.id, name: task.name }); + }); + andThen(() => { + Task.breadcrumbFor('jobs.job.index').visit(); + }); + andThen(() => { + assert.equal( + currentURL(), + `/jobs/${job.id}?namespace=other-namespace`, + 'Job breadcrumb links correctly' + ); + }); + andThen(() => { + Task.visit({ id: allocation.id, name: task.name }); + }); + andThen(() => { + Task.breadcrumbFor('jobs.job.task-group').visit(); + }); + andThen(() => { + assert.equal( + currentURL(), + `/jobs/${job.id}/${taskGroup}?namespace=other-namespace`, + 'Task Group breadcrumb links correctly' + ); + }); + andThen(() => { + Task.visit({ id: allocation.id, name: task.name }); + }); + andThen(() => { + Task.breadcrumbFor('allocations.allocation').visit(); + }); + andThen(() => { + assert.equal( + currentURL(), + `/allocations/${allocation.id}`, + 'Allocations breadcrumb links correctly' + ); + }); +});