Skip to content

Commit

Permalink
Changing namespaces now situationally redirects to jobs or volumes
Browse files Browse the repository at this point in the history
Changing namespaces can be done anywhere in the app even though many
Nomad resources aren't namespace-sensitive (e.g., clients, plugins).

A user changing namespaces is an intent to reset context, "now I want
to begin a task that relates to Namespace X". Where that task begins
used to always be the Jobs list, since it was the only namespace
sensitive resource. Now with CSI Volumes, "square 1" is Volumes if the
namespace is changed from a storage page.
  • Loading branch information
DingoEatingFuzz committed May 8, 2020
1 parent 79327c9 commit 9f371c3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ui/app/components/gutter-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ export default Component.extend({
gotoJobsForNamespace(namespace) {
if (!namespace || !namespace.get('id')) return;

this.router.transitionTo('jobs', {
// Jobs and CSI Volumes are both namespace-sensitive. Changing namespaces is
// an intent to reset context, but where to reset to depends on where the namespace
// is being switched from. Jobs take precedence, but if the namespace is switched from
// a storage-related page, context should be reset to volumes.
const destination = this.router.currentRouteName.startsWith('csi.') ? 'csi.volumes' : 'jobs';

this.router.transitionTo(destination, {
queryParams: { namespace: namespace.get('id') },
});
},
Expand Down
56 changes: 56 additions & 0 deletions ui/tests/acceptance/namespaces-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { selectChoose } from 'ember-power-select/test-support';
import JobsList from 'nomad-ui/tests/pages/jobs/list';
import ClientsList from 'nomad-ui/tests/pages/clients/list';
import Allocation from 'nomad-ui/tests/pages/allocations/detail';
import PluginsList from 'nomad-ui/tests/pages/storage/plugins/list';
import VolumesList from 'nomad-ui/tests/pages/storage/volumes/list';

module('Acceptance | namespaces (disabled)', function(hooks) {
setupApplicationTest(hooks);
Expand Down Expand Up @@ -38,6 +43,10 @@ module('Acceptance | namespaces (enabled)', function(hooks) {
server.createList('job', 5);
});

hooks.afterEach(function() {
window.localStorage.clear();
});

test('the namespace switcher lists all namespaces', async function(assert) {
const namespaces = server.db.namespaces;

Expand Down Expand Up @@ -105,4 +114,51 @@ module('Acceptance | namespaces (enabled)', function(hooks) {
'Namespace query param on second request'
);
});

test('changing the namespace in the clients hierarchy navigates to the jobs page', async function(assert) {
const namespace = server.db.namespaces[1];

await ClientsList.visit();
await selectChoose('[data-test-namespace-switcher]', namespace.name);

assert.equal(currentURL(), `/jobs?namespace=${namespace.name}`);
});

test('changing the namespace in the allocations hierarchy navigates to the jobs page', async function(assert) {
const namespace = server.db.namespaces[1];
const allocation = server.create('allocation', { job: server.db.jobs[0] });

await Allocation.visit({ id: allocation.id });
await selectChoose('[data-test-namespace-switcher]', namespace.name);

assert.equal(currentURL(), `/jobs?namespace=${namespace.name}`);
});

test('changing the namespace in the storage hierarchy navigates to the volumes page', async function(assert) {
const namespace = server.db.namespaces[1];

await PluginsList.visit();
await selectChoose('[data-test-namespace-switcher]', namespace.name);

assert.equal(currentURL(), `/csi/volumes?namespace=${namespace.name}`);
});

test('changing the namespace refreshes the volumes list when on the volumes page', async function(assert) {
const namespace = server.db.namespaces[1];

await VolumesList.visit();

let requests = server.pretender.handledRequests.filter(req =>
req.url.startsWith('/v1/volumes')
);
assert.equal(requests.length, 1);
assert.equal(requests[0].queryParams.namespace, undefined);

// TODO: handle this with Page Objects
await selectChoose('[data-test-namespace-switcher]', namespace.name);

requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/volumes'));
assert.equal(requests.length, 2);
assert.equal(requests[1].queryParams.namespace, namespace.name);
});
});

0 comments on commit 9f371c3

Please sign in to comment.