github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/acceptance/volumes-list-test.js (about) 1 import { currentURL, visit } 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 pageSizeSelect from './behaviors/page-size-select'; 7 import VolumesList from 'nomad-ui/tests/pages/storage/volumes/list'; 8 import Layout from 'nomad-ui/tests/pages/layout'; 9 10 const assignWriteAlloc = (volume, alloc) => { 11 volume.writeAllocs.add(alloc); 12 volume.allocations.add(alloc); 13 volume.save(); 14 }; 15 16 const assignReadAlloc = (volume, alloc) => { 17 volume.readAllocs.add(alloc); 18 volume.allocations.add(alloc); 19 volume.save(); 20 }; 21 22 module('Acceptance | volumes list', function(hooks) { 23 setupApplicationTest(hooks); 24 setupMirage(hooks); 25 26 hooks.beforeEach(function() { 27 server.create('node'); 28 server.create('csi-plugin', { createVolumes: false }); 29 window.localStorage.clear(); 30 }); 31 32 test('it passes an accessibility audit', async function(assert) { 33 await VolumesList.visit(); 34 await a11yAudit(assert); 35 }); 36 37 test('visiting /csi redirects to /csi/volumes', async function(assert) { 38 await visit('/csi'); 39 40 assert.equal(currentURL(), '/csi/volumes'); 41 }); 42 43 test('visiting /csi/volumes', async function(assert) { 44 await VolumesList.visit(); 45 46 assert.equal(currentURL(), '/csi/volumes'); 47 assert.equal(document.title, 'CSI Volumes - Nomad'); 48 }); 49 50 test('/csi/volumes should list the first page of volumes sorted by name', async function(assert) { 51 const volumeCount = VolumesList.pageSize + 1; 52 server.createList('csi-volume', volumeCount); 53 54 await VolumesList.visit(); 55 56 const sortedVolumes = server.db.csiVolumes.sortBy('id'); 57 assert.equal(VolumesList.volumes.length, VolumesList.pageSize); 58 VolumesList.volumes.forEach((volume, index) => { 59 assert.equal(volume.name, sortedVolumes[index].id, 'Volumes are ordered'); 60 }); 61 }); 62 63 test('each volume row should contain information about the volume', async function(assert) { 64 const volume = server.create('csi-volume'); 65 const readAllocs = server.createList('allocation', 2, { shallow: true }); 66 const writeAllocs = server.createList('allocation', 3, { shallow: true }); 67 readAllocs.forEach(alloc => assignReadAlloc(volume, alloc)); 68 writeAllocs.forEach(alloc => assignWriteAlloc(volume, alloc)); 69 70 await VolumesList.visit(); 71 72 const volumeRow = VolumesList.volumes.objectAt(0); 73 74 let controllerHealthStr = 'Node Only'; 75 if (volume.controllerRequired || volume.controllersExpected > 0) { 76 const healthy = volume.controllersHealthy; 77 const expected = volume.controllersExpected; 78 const isHealthy = healthy > 0; 79 controllerHealthStr = `${isHealthy ? 'Healthy' : 'Unhealthy'} (${healthy}/${expected})`; 80 } 81 82 const nodeHealthStr = volume.nodesHealthy > 0 ? 'Healthy' : 'Unhealthy'; 83 84 assert.equal(volumeRow.name, volume.id); 85 assert.equal(volumeRow.schedulable, volume.schedulable ? 'Schedulable' : 'Unschedulable'); 86 assert.equal(volumeRow.controllerHealth, controllerHealthStr); 87 assert.equal( 88 volumeRow.nodeHealth, 89 `${nodeHealthStr} (${volume.nodesHealthy}/${volume.nodesExpected})` 90 ); 91 assert.equal(volumeRow.provider, volume.provider); 92 assert.equal(volumeRow.allocations, readAllocs.length + writeAllocs.length); 93 }); 94 95 test('each volume row should link to the corresponding volume', async function(assert) { 96 const volume = server.create('csi-volume'); 97 98 await VolumesList.visit(); 99 100 await VolumesList.volumes.objectAt(0).clickName(); 101 assert.equal(currentURL(), `/csi/volumes/${volume.id}`); 102 103 await VolumesList.visit(); 104 assert.equal(currentURL(), '/csi/volumes'); 105 106 await VolumesList.volumes.objectAt(0).clickRow(); 107 assert.equal(currentURL(), `/csi/volumes/${volume.id}`); 108 }); 109 110 test('when there are no volumes, there is an empty message', async function(assert) { 111 await VolumesList.visit(); 112 113 assert.ok(VolumesList.isEmpty); 114 assert.equal(VolumesList.emptyState.headline, 'No Volumes'); 115 }); 116 117 test('when there are volumes, but no matches for a search, there is an empty message', async function(assert) { 118 server.create('csi-volume', { id: 'cat 1' }); 119 server.create('csi-volume', { id: 'cat 2' }); 120 121 await VolumesList.visit(); 122 123 await VolumesList.search('dog'); 124 assert.ok(VolumesList.isEmpty); 125 assert.equal(VolumesList.emptyState.headline, 'No Matches'); 126 }); 127 128 test('searching resets the current page', async function(assert) { 129 server.createList('csi-volume', VolumesList.pageSize + 1); 130 131 await VolumesList.visit(); 132 await VolumesList.nextPage(); 133 134 assert.equal(currentURL(), '/csi/volumes?page=2'); 135 136 await VolumesList.search('foobar'); 137 138 assert.equal(currentURL(), '/csi/volumes?search=foobar'); 139 }); 140 141 test('when the namespace query param is set, only matching volumes are shown and the namespace value is forwarded to app state', async function(assert) { 142 server.createList('namespace', 2); 143 const volume1 = server.create('csi-volume', { namespaceId: server.db.namespaces[0].id }); 144 const volume2 = server.create('csi-volume', { namespaceId: server.db.namespaces[1].id }); 145 146 await VolumesList.visit(); 147 148 assert.equal(VolumesList.volumes.length, 1); 149 assert.equal(VolumesList.volumes.objectAt(0).name, volume1.id); 150 151 const secondNamespace = server.db.namespaces[1]; 152 await VolumesList.visit({ namespace: secondNamespace.id }); 153 154 assert.equal(VolumesList.volumes.length, 1); 155 assert.equal(VolumesList.volumes.objectAt(0).name, volume2.id); 156 }); 157 158 test('the active namespace is carried over to the jobs pages', async function(assert) { 159 server.createList('namespace', 2); 160 161 const namespace = server.db.namespaces[1]; 162 await VolumesList.visit({ namespace: namespace.id }); 163 164 await Layout.gutter.visitJobs(); 165 166 assert.equal(currentURL(), `/jobs?namespace=${namespace.id}`); 167 }); 168 169 test('when accessing volumes is forbidden, a message is shown with a link to the tokens page', async function(assert) { 170 server.pretender.get('/v1/volumes', () => [403, {}, null]); 171 172 await VolumesList.visit(); 173 assert.equal(VolumesList.error.title, 'Not Authorized'); 174 175 await VolumesList.error.seekHelp(); 176 assert.equal(currentURL(), '/settings/tokens'); 177 }); 178 179 pageSizeSelect({ 180 resourceName: 'volume', 181 pageObject: VolumesList, 182 pageObjectList: VolumesList.volumes, 183 async setup() { 184 server.createList('csi-volume', VolumesList.pageSize); 185 await VolumesList.visit(); 186 }, 187 }); 188 });