github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/tests/acceptance/namespaces-test.js (about) 1 import { module, test } from 'qunit'; 2 import { setupApplicationTest } from 'ember-qunit'; 3 import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; 4 import { selectChoose } from 'ember-power-select/test-support'; 5 import JobsList from 'nomad-ui/tests/pages/jobs/list'; 6 7 module('Acceptance | namespaces (disabled)', function(hooks) { 8 setupApplicationTest(hooks); 9 setupMirage(hooks); 10 11 hooks.beforeEach(function() { 12 server.create('agent'); 13 server.create('node'); 14 server.createList('job', 5, { createAllocations: false }); 15 }); 16 17 test('the namespace switcher is not in the gutter menu', async function(assert) { 18 await JobsList.visit(); 19 assert.notOk(JobsList.namespaceSwitcher.isPresent, 'No namespace switcher found'); 20 }); 21 22 test('the jobs request is made with no query params', async function(assert) { 23 await JobsList.visit(); 24 25 const request = server.pretender.handledRequests.findBy('url', '/v1/jobs'); 26 assert.equal(request.queryParams.namespace, undefined, 'No namespace query param'); 27 }); 28 }); 29 30 module('Acceptance | namespaces (enabled)', function(hooks) { 31 setupApplicationTest(hooks); 32 setupMirage(hooks); 33 34 hooks.beforeEach(function() { 35 server.createList('namespace', 3); 36 server.create('agent'); 37 server.create('node'); 38 server.createList('job', 5); 39 }); 40 41 test('the namespace switcher lists all namespaces', async function(assert) { 42 const namespaces = server.db.namespaces; 43 44 await JobsList.visit(); 45 46 assert.ok(JobsList.namespaceSwitcher.isPresent, 'Namespace switcher found'); 47 await JobsList.namespaceSwitcher.open(); 48 // TODO this selector should be scoped to only the namespace switcher options, 49 // but ember-wormhole makes that difficult. 50 assert.equal( 51 JobsList.namespaceSwitcher.options.length, 52 namespaces.length, 53 'All namespaces are in the switcher' 54 ); 55 assert.equal( 56 JobsList.namespaceSwitcher.options.objectAt(0).label, 57 'Default Namespace', 58 'The first namespace is always the default one' 59 ); 60 61 const sortedNamespaces = namespaces.slice(1).sortBy('name'); 62 JobsList.namespaceSwitcher.options.forEach((option, index) => { 63 // Default Namespace handled separately 64 if (index === 0) return; 65 66 const namespace = sortedNamespaces[index - 1]; 67 assert.equal(option.label, namespace.name, `index ${index}: ${namespace.name}`); 68 }); 69 }); 70 71 test('changing the namespace sets the namespace in localStorage', async function(assert) { 72 const namespace = server.db.namespaces[1]; 73 74 await JobsList.visit(); 75 await selectChoose('[data-test-namespace-switcher]', namespace.name); 76 77 assert.equal( 78 window.localStorage.nomadActiveNamespace, 79 namespace.id, 80 'Active namespace was set' 81 ); 82 }); 83 84 test('changing the namespace refreshes the jobs list when on the jobs page', async function(assert) { 85 const namespace = server.db.namespaces[1]; 86 87 await JobsList.visit(); 88 89 let requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs')); 90 assert.equal(requests.length, 1, 'First request to jobs'); 91 assert.equal( 92 requests[0].queryParams.namespace, 93 undefined, 94 'Namespace query param is defaulted to "default"/undefined' 95 ); 96 97 // TODO: handle this with Page Objects 98 await selectChoose('[data-test-namespace-switcher]', namespace.name); 99 100 requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs')); 101 assert.equal(requests.length, 2, 'Second request to jobs'); 102 assert.equal( 103 requests[1].queryParams.namespace, 104 namespace.name, 105 'Namespace query param on second request' 106 ); 107 }); 108 });