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