2020-05-08 04:18:55 +00:00
|
|
|
import { currentURL } from '@ember/test-helpers';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2019-09-26 18:47:07 +00:00
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2020-07-28 17:59:14 +00:00
|
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
2019-03-14 06:44:53 +00:00
|
|
|
import { selectChoose } from 'ember-power-select/test-support';
|
2018-07-11 18:59:20 +00:00
|
|
|
import JobsList from 'nomad-ui/tests/pages/jobs/list';
|
2020-05-08 04:18:55 +00:00
|
|
|
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';
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Acceptance | namespaces (disabled)', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
2017-10-11 17:12:10 +00:00
|
|
|
server.create('agent');
|
|
|
|
server.create('node');
|
2019-04-12 03:08:43 +00:00
|
|
|
server.createList('job', 5, { createAllocations: false });
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the namespace switcher is not in the gutter menu', async function(assert) {
|
|
|
|
await JobsList.visit();
|
2018-07-11 18:59:20 +00:00
|
|
|
assert.notOk(JobsList.namespaceSwitcher.isPresent, 'No namespace switcher found');
|
2017-10-11 17:12:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the jobs request is made with no query params', async function(assert) {
|
|
|
|
await JobsList.visit();
|
2017-10-11 17:12:10 +00:00
|
|
|
|
|
|
|
const request = server.pretender.handledRequests.findBy('url', '/v1/jobs');
|
|
|
|
assert.equal(request.queryParams.namespace, undefined, 'No namespace query param');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Acceptance | namespaces (enabled)', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-14 06:44:53 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
2017-10-11 17:12:10 +00:00
|
|
|
server.createList('namespace', 3);
|
|
|
|
server.create('agent');
|
|
|
|
server.create('node');
|
|
|
|
server.createList('job', 5);
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2020-05-08 04:18:55 +00:00
|
|
|
hooks.afterEach(function() {
|
|
|
|
window.localStorage.clear();
|
|
|
|
});
|
|
|
|
|
2020-07-28 17:59:14 +00:00
|
|
|
test('it passes an accessibility audit', async function(assert) {
|
|
|
|
await JobsList.visit();
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('the namespace switcher lists all namespaces', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const namespaces = server.db.namespaces;
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2018-07-11 18:59:20 +00:00
|
|
|
assert.ok(JobsList.namespaceSwitcher.isPresent, 'Namespace switcher found');
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.namespaceSwitcher.open();
|
2017-10-11 17:12:10 +00:00
|
|
|
// TODO this selector should be scoped to only the namespace switcher options,
|
|
|
|
// but ember-wormhole makes that difficult.
|
|
|
|
assert.equal(
|
2018-07-11 18:59:20 +00:00
|
|
|
JobsList.namespaceSwitcher.options.length,
|
2017-10-11 17:12:10 +00:00
|
|
|
namespaces.length,
|
|
|
|
'All namespaces are in the switcher'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2018-07-11 18:59:20 +00:00
|
|
|
JobsList.namespaceSwitcher.options.objectAt(0).label,
|
2017-10-11 17:12:10 +00:00
|
|
|
'Default Namespace',
|
|
|
|
'The first namespace is always the default one'
|
|
|
|
);
|
|
|
|
|
2018-07-11 18:59:20 +00:00
|
|
|
const sortedNamespaces = namespaces.slice(1).sortBy('name');
|
|
|
|
JobsList.namespaceSwitcher.options.forEach((option, index) => {
|
|
|
|
// Default Namespace handled separately
|
|
|
|
if (index === 0) return;
|
|
|
|
|
|
|
|
const namespace = sortedNamespaces[index - 1];
|
|
|
|
assert.equal(option.label, namespace.name, `index ${index}: ${namespace.name}`);
|
|
|
|
});
|
2017-10-11 17:12:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('changing the namespace sets the namespace in localStorage', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const namespace = server.db.namespaces[1];
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
|
|
|
await selectChoose('[data-test-namespace-switcher]', namespace.name);
|
2017-10-11 17:12:10 +00:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
window.localStorage.nomadActiveNamespace,
|
|
|
|
namespace.id,
|
|
|
|
'Active namespace was set'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('changing the namespace refreshes the jobs list when on the jobs page', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const namespace = server.db.namespaces[1];
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2019-03-13 00:40:39 +00:00
|
|
|
let requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs'));
|
2017-10-11 17:12:10 +00:00
|
|
|
assert.equal(requests.length, 1, 'First request to jobs');
|
|
|
|
assert.equal(
|
|
|
|
requests[0].queryParams.namespace,
|
2017-10-23 17:30:11 +00:00
|
|
|
undefined,
|
|
|
|
'Namespace query param is defaulted to "default"/undefined'
|
2017-10-11 17:12:10 +00:00
|
|
|
);
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
// TODO: handle this with Page Objects
|
2019-03-14 06:44:53 +00:00
|
|
|
await selectChoose('[data-test-namespace-switcher]', namespace.name);
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2019-03-13 00:40:39 +00:00
|
|
|
requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs'));
|
2017-10-11 17:12:10 +00:00
|
|
|
assert.equal(requests.length, 2, 'Second request to jobs');
|
|
|
|
assert.equal(
|
|
|
|
requests[1].queryParams.namespace,
|
|
|
|
namespace.name,
|
|
|
|
'Namespace query param on second request'
|
|
|
|
);
|
|
|
|
});
|
2020-05-08 04:18:55 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2017-10-11 17:12:10 +00:00
|
|
|
});
|