github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/acceptance/namespaces-test.js (about) 1 import { currentURL } from '@ember/test-helpers'; 2 import { module, test } from 'qunit'; 3 import { setupApplicationTest } from 'ember-qunit'; 4 import { setupMirage } from 'ember-cli-mirage/test-support'; 5 import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; 6 import { selectChoose } from 'ember-power-select/test-support'; 7 import JobsList from 'nomad-ui/tests/pages/jobs/list'; 8 import ClientsList from 'nomad-ui/tests/pages/clients/list'; 9 import Allocation from 'nomad-ui/tests/pages/allocations/detail'; 10 import PluginsList from 'nomad-ui/tests/pages/storage/plugins/list'; 11 import VolumesList from 'nomad-ui/tests/pages/storage/volumes/list'; 12 13 module('Acceptance | namespaces (disabled)', function(hooks) { 14 setupApplicationTest(hooks); 15 setupMirage(hooks); 16 17 hooks.beforeEach(function() { 18 server.create('agent'); 19 server.create('node'); 20 server.createList('job', 5, { createAllocations: false }); 21 }); 22 23 test('the namespace switcher is not in the gutter menu', async function(assert) { 24 await JobsList.visit(); 25 assert.notOk(JobsList.namespaceSwitcher.isPresent, 'No namespace switcher found'); 26 }); 27 28 test('the jobs request is made with no query params', async function(assert) { 29 await JobsList.visit(); 30 31 const request = server.pretender.handledRequests.findBy('url', '/v1/jobs'); 32 assert.equal(request.queryParams.namespace, undefined, 'No namespace query param'); 33 }); 34 }); 35 36 module('Acceptance | namespaces (enabled)', function(hooks) { 37 setupApplicationTest(hooks); 38 setupMirage(hooks); 39 40 hooks.beforeEach(function() { 41 server.createList('namespace', 3); 42 server.create('agent'); 43 server.create('node'); 44 server.createList('job', 5); 45 }); 46 47 hooks.afterEach(function() { 48 window.localStorage.clear(); 49 }); 50 51 test('it passes an accessibility audit', async function(assert) { 52 await JobsList.visit(); 53 await a11yAudit(assert); 54 }); 55 56 test('the namespace switcher lists all namespaces', async function(assert) { 57 const namespaces = server.db.namespaces; 58 59 await JobsList.visit(); 60 61 assert.ok(JobsList.namespaceSwitcher.isPresent, 'Namespace switcher found'); 62 await JobsList.namespaceSwitcher.open(); 63 // TODO this selector should be scoped to only the namespace switcher options, 64 // but ember-wormhole makes that difficult. 65 assert.equal( 66 JobsList.namespaceSwitcher.options.length, 67 namespaces.length, 68 'All namespaces are in the switcher' 69 ); 70 assert.equal( 71 JobsList.namespaceSwitcher.options.objectAt(0).label, 72 'Namespace: default', 73 'The first namespace is always the default one' 74 ); 75 76 const sortedNamespaces = namespaces.slice(1).sortBy('name'); 77 JobsList.namespaceSwitcher.options.forEach((option, index) => { 78 // Default Namespace handled separately 79 if (index === 0) return; 80 81 const namespace = sortedNamespaces[index - 1]; 82 assert.equal( 83 option.label, 84 `Namespace: ${namespace.name}`, 85 `index ${index}: ${namespace.name}` 86 ); 87 }); 88 }); 89 90 test('changing the namespace sets the namespace in localStorage', async function(assert) { 91 const namespace = server.db.namespaces[1]; 92 93 await JobsList.visit(); 94 await selectChoose('[data-test-namespace-switcher]', namespace.name); 95 96 assert.equal( 97 window.localStorage.nomadActiveNamespace, 98 namespace.id, 99 'Active namespace was set' 100 ); 101 }); 102 103 test('changing the namespace refreshes the jobs list when on the jobs page', async function(assert) { 104 const namespace = server.db.namespaces[1]; 105 106 await JobsList.visit(); 107 108 let requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs')); 109 assert.equal(requests.length, 1, 'First request to jobs'); 110 assert.equal( 111 requests[0].queryParams.namespace, 112 undefined, 113 'Namespace query param is defaulted to "default"/undefined' 114 ); 115 116 // TODO: handle this with Page Objects 117 await selectChoose('[data-test-namespace-switcher]', namespace.name); 118 119 requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs')); 120 assert.equal(requests.length, 2, 'Second request to jobs'); 121 assert.equal( 122 requests[1].queryParams.namespace, 123 namespace.name, 124 'Namespace query param on second request' 125 ); 126 }); 127 128 test('changing the namespace in the clients hierarchy navigates to the jobs page', async function(assert) { 129 const namespace = server.db.namespaces[1]; 130 131 await ClientsList.visit(); 132 await selectChoose('[data-test-namespace-switcher]', namespace.name); 133 134 assert.equal(currentURL(), `/jobs?namespace=${namespace.name}`); 135 }); 136 137 test('changing the namespace in the allocations hierarchy navigates to the jobs page', async function(assert) { 138 const namespace = server.db.namespaces[1]; 139 const allocation = server.create('allocation', { job: server.db.jobs[0] }); 140 141 await Allocation.visit({ id: allocation.id }); 142 await selectChoose('[data-test-namespace-switcher]', namespace.name); 143 144 assert.equal(currentURL(), `/jobs?namespace=${namespace.name}`); 145 }); 146 147 test('changing the namespace in the storage hierarchy navigates to the volumes page', async function(assert) { 148 const namespace = server.db.namespaces[1]; 149 150 await PluginsList.visit(); 151 await selectChoose('[data-test-namespace-switcher]', namespace.name); 152 153 assert.equal(currentURL(), `/csi/volumes?namespace=${namespace.name}`); 154 }); 155 156 test('changing the namespace refreshes the volumes list when on the volumes page', async function(assert) { 157 const namespace = server.db.namespaces[1]; 158 159 await VolumesList.visit(); 160 161 let requests = server.pretender.handledRequests.filter(req => 162 req.url.startsWith('/v1/volumes') 163 ); 164 assert.equal(requests.length, 1); 165 assert.equal(requests[0].queryParams.namespace, undefined); 166 167 // TODO: handle this with Page Objects 168 await selectChoose('[data-test-namespace-switcher]', namespace.name); 169 170 requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/volumes')); 171 assert.equal(requests.length, 2); 172 assert.equal(requests[1].queryParams.namespace, namespace.name); 173 }); 174 });