Skip to content

Commit

Permalink
[ui] links to allocations explicitly go through their route model hook (
Browse files Browse the repository at this point in the history
#17737)

* links to allocations explicitly go through their route model hook

* Acceptance test to make sure alloc clicking loads alloc endpoint obj
  • Loading branch information
philrenaud authored Jun 27, 2023
1 parent 6b06b02 commit 72a9f2b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ui/app/controllers/clients/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default class ClientController extends Controller.extend(
@action
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);
this.transitionToRoute('allocations.allocation', allocation.id);
}
@action
Expand Down
2 changes: 1 addition & 1 deletion ui/app/controllers/csi/plugins/plugin/allocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class AllocationsController extends Controller.extend(
@action
gotoAllocation(allocation, event) {
lazyClick([
() => this.transitionToRoute('allocations.allocation', allocation),
() => this.transitionToRoute('allocations.allocation', allocation.id),
event,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/controllers/csi/plugins/plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export default class IndexController extends Controller {

@action
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);
this.transitionToRoute('allocations.allocation', allocation.id);
}
}
2 changes: 1 addition & 1 deletion ui/app/controllers/csi/volumes/volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ export default class VolumeController extends Controller {

@action
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);
this.transitionToRoute('allocations.allocation', allocation.id);
}
}
2 changes: 1 addition & 1 deletion ui/app/controllers/jobs/job/allocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class AllocationsController extends Controller.extend(

@action
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);
this.transitionToRoute('allocations.allocation', allocation.id);
}

get optionsAllocationStatus() {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/controllers/jobs/job/task-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default class TaskGroupController extends Controller.extend(

@action
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);
this.transitionToRoute('allocations.allocation', allocation.id);
}

@action
Expand Down
3 changes: 3 additions & 0 deletions ui/app/routes/allocations/allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export default class AllocationRoute extends Route.extend(WithWatchers) {
super.model(...arguments),
this.store.findAll('namespace'),
]);
if (allocation.isPartial) {
await allocation.reload();
}
const jobId = allocation.belongsTo('job').id();
await this.store.findRecord('job', jobId);
return allocation;
Expand Down
29 changes: 28 additions & 1 deletion ui/tests/acceptance/job-allocations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { currentURL, click, find } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
Expand Down Expand Up @@ -77,6 +77,33 @@ module('Acceptance | job allocations', function (hooks) {
assert.equal(document.title, `Job ${job.name} allocations - Nomad`);
});

test('clicking an allocation results in the correct endpoint being hit', async function (assert) {
server.createList('allocation', Allocations.pageSize - 1, {
shallow: true,
});
allocations = server.schema.allocations.where({ jobId: job.id }).models;

await Allocations.visit({ id: job.id });

const firstAllocation = find('[data-test-allocation]');
await click(firstAllocation);

const requestToAllocationEndpoint = server.pretender.handledRequests.find(
(request) =>
request.url.includes(
`/v1/allocation/${firstAllocation.dataset.testAllocation}`
)
);

assert.ok(requestToAllocationEndpoint, 'the correct endpoint is hit');

assert.equal(
currentURL(),
`/allocations/${firstAllocation.dataset.testAllocation}`,
'the URL is correct'
);
});

test('allocations table is sortable', async function (assert) {
server.createList('allocation', Allocations.pageSize - 1);
allocations = server.schema.allocations.where({ jobId: job.id }).models;
Expand Down

0 comments on commit 72a9f2b

Please sign in to comment.