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