2017-10-11 17:12:10 +00:00
|
|
|
import { test } from 'qunit';
|
|
|
|
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
|
2018-07-11 18:59:20 +00:00
|
|
|
import JobsList from 'nomad-ui/tests/pages/jobs/list';
|
2017-10-11 17:12:10 +00:00
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | namespaces (disabled)', {
|
|
|
|
beforeEach() {
|
|
|
|
server.create('agent');
|
|
|
|
server.create('node');
|
|
|
|
server.createList('job', 5);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the namespace switcher is not in the gutter menu', function(assert) {
|
2018-07-11 18:59:20 +00:00
|
|
|
JobsList.visit();
|
2017-10-11 17:12:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the jobs request is made with no query params', function(assert) {
|
2018-07-11 18:59:20 +00:00
|
|
|
JobsList.visit();
|
2017-10-11 17:12:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const request = server.pretender.handledRequests.findBy('url', '/v1/jobs');
|
|
|
|
assert.equal(request.queryParams.namespace, undefined, 'No namespace query param');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | namespaces (enabled)', {
|
|
|
|
beforeEach() {
|
|
|
|
server.createList('namespace', 3);
|
|
|
|
server.create('agent');
|
|
|
|
server.create('node');
|
|
|
|
server.createList('job', 5);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the namespace switcher lists all namespaces', function(assert) {
|
|
|
|
const namespaces = server.db.namespaces;
|
|
|
|
|
2018-07-11 18:59:20 +00:00
|
|
|
JobsList.visit();
|
2017-10-11 17:12:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 18:59:20 +00:00
|
|
|
assert.ok(JobsList.namespaceSwitcher.isPresent, 'Namespace switcher found');
|
2017-10-11 17:12:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-07-11 18:59:20 +00:00
|
|
|
JobsList.namespaceSwitcher.open();
|
2017-10-11 17:12:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
// 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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('changing the namespace sets the namespace in localStorage', function(assert) {
|
|
|
|
const namespace = server.db.namespaces[1];
|
|
|
|
|
2018-07-11 18:59:20 +00:00
|
|
|
JobsList.visit();
|
2017-10-11 17:12:10 +00:00
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
selectChoose('[data-test-namespace-switcher]', namespace.name);
|
2017-10-11 17:12:10 +00:00
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
window.localStorage.nomadActiveNamespace,
|
|
|
|
namespace.id,
|
|
|
|
'Active namespace was set'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('changing the namespace refreshes the jobs list when on the jobs page', function(assert) {
|
|
|
|
const namespace = server.db.namespaces[1];
|
|
|
|
|
2018-07-11 18:59:20 +00:00
|
|
|
JobsList.visit();
|
2017-10-11 17:12:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs'));
|
|
|
|
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
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-07-11 18:59:20 +00:00
|
|
|
// TODO: handle this with Page Objects
|
2018-01-05 20:59:36 +00:00
|
|
|
selectChoose('[data-test-namespace-switcher]', namespace.name);
|
2017-10-11 17:12:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs'));
|
|
|
|
assert.equal(requests.length, 2, 'Second request to jobs');
|
|
|
|
assert.equal(
|
|
|
|
requests[1].queryParams.namespace,
|
|
|
|
namespace.name,
|
|
|
|
'Namespace query param on second request'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|