github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/acceptance/plugins-list-test.js (about) 1 /* eslint-disable qunit/require-expect */ 2 import { currentURL } from '@ember/test-helpers'; 3 import { module, test } from 'qunit'; 4 import { setupApplicationTest } from 'ember-qunit'; 5 import { setupMirage } from 'ember-cli-mirage/test-support'; 6 import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; 7 import pageSizeSelect from './behaviors/page-size-select'; 8 import PluginsList from 'nomad-ui/tests/pages/storage/plugins/list'; 9 10 module('Acceptance | plugins list', function (hooks) { 11 setupApplicationTest(hooks); 12 setupMirage(hooks); 13 14 hooks.beforeEach(function () { 15 server.create('node'); 16 window.localStorage.clear(); 17 }); 18 19 test('it passes an accessibility audit', async function (assert) { 20 await PluginsList.visit(); 21 await a11yAudit(assert); 22 }); 23 24 test('visiting /csi/plugins', async function (assert) { 25 await PluginsList.visit(); 26 27 assert.equal(currentURL(), '/csi/plugins'); 28 assert.equal(document.title, 'CSI Plugins - Nomad'); 29 }); 30 31 test('/csi/plugins should list the first page of plugins sorted by id', async function (assert) { 32 const pluginCount = PluginsList.pageSize + 1; 33 server.createList('csi-plugin', pluginCount, { shallow: true }); 34 35 await PluginsList.visit(); 36 37 const sortedPlugins = server.db.csiPlugins.sortBy('id'); 38 assert.equal(PluginsList.plugins.length, PluginsList.pageSize); 39 PluginsList.plugins.forEach((plugin, index) => { 40 assert.equal(plugin.id, sortedPlugins[index].id, 'Plugins are ordered'); 41 }); 42 }); 43 44 test('each plugin row should contain information about the plugin', async function (assert) { 45 const plugin = server.create('csi-plugin', { 46 shallow: true, 47 controllerRequired: true, 48 }); 49 50 await PluginsList.visit(); 51 52 const pluginRow = PluginsList.plugins.objectAt(0); 53 const controllerHealthStr = 54 plugin.controllersHealthy > 0 ? 'Healthy' : 'Unhealthy'; 55 const nodeHealthStr = plugin.nodesHealthy > 0 ? 'Healthy' : 'Unhealthy'; 56 57 assert.equal(pluginRow.id, plugin.id); 58 assert.equal( 59 pluginRow.controllerHealth, 60 `${controllerHealthStr} (${plugin.controllersHealthy}/${plugin.controllersExpected})` 61 ); 62 assert.equal( 63 pluginRow.nodeHealth, 64 `${nodeHealthStr} (${plugin.nodesHealthy}/${plugin.nodesExpected})` 65 ); 66 assert.equal(pluginRow.provider, plugin.provider); 67 }); 68 69 test('node only plugins explain that there is no controller health for this plugin type', async function (assert) { 70 const plugin = server.create('csi-plugin', { 71 shallow: true, 72 controllerRequired: false, 73 }); 74 75 await PluginsList.visit(); 76 77 const pluginRow = PluginsList.plugins.objectAt(0); 78 const nodeHealthStr = plugin.nodesHealthy > 0 ? 'Healthy' : 'Unhealthy'; 79 80 assert.equal(pluginRow.id, plugin.id); 81 assert.equal(pluginRow.controllerHealth, 'Node Only'); 82 assert.equal( 83 pluginRow.nodeHealth, 84 `${nodeHealthStr} (${plugin.nodesHealthy}/${plugin.nodesExpected})` 85 ); 86 assert.equal(pluginRow.provider, plugin.provider); 87 }); 88 89 test('each plugin row should link to the corresponding plugin', async function (assert) { 90 const plugin = server.create('csi-plugin', { shallow: true }); 91 92 await PluginsList.visit(); 93 94 await PluginsList.plugins.objectAt(0).clickName(); 95 assert.equal(currentURL(), `/csi/plugins/${plugin.id}`); 96 97 await PluginsList.visit(); 98 assert.equal(currentURL(), '/csi/plugins'); 99 100 await PluginsList.plugins.objectAt(0).clickRow(); 101 assert.equal(currentURL(), `/csi/plugins/${plugin.id}`); 102 }); 103 104 test('when there are no plugins, there is an empty message', async function (assert) { 105 await PluginsList.visit(); 106 107 assert.ok(PluginsList.isEmpty); 108 assert.equal(PluginsList.emptyState.headline, 'No Plugins'); 109 }); 110 111 test('when there are plugins, but no matches for a search, there is an empty message', async function (assert) { 112 server.create('csi-plugin', { id: 'cat 1', shallow: true }); 113 server.create('csi-plugin', { id: 'cat 2', shallow: true }); 114 115 await PluginsList.visit(); 116 117 await PluginsList.search('dog'); 118 assert.ok(PluginsList.isEmpty); 119 assert.equal(PluginsList.emptyState.headline, 'No Matches'); 120 }); 121 122 test('search resets the current page', async function (assert) { 123 server.createList('csi-plugin', PluginsList.pageSize + 1, { 124 shallow: true, 125 }); 126 127 await PluginsList.visit(); 128 await PluginsList.nextPage(); 129 130 assert.equal(currentURL(), '/csi/plugins?page=2'); 131 132 await PluginsList.search('foobar'); 133 134 assert.equal(currentURL(), '/csi/plugins?search=foobar'); 135 }); 136 137 test('when accessing plugins is forbidden, a message is shown with a link to the tokens page', async function (assert) { 138 server.pretender.get('/v1/plugins', () => [403, {}, null]); 139 140 await PluginsList.visit(); 141 assert.equal(PluginsList.error.title, 'Not Authorized'); 142 143 await PluginsList.error.seekHelp(); 144 assert.equal(currentURL(), '/settings/tokens'); 145 }); 146 147 pageSizeSelect({ 148 resourceName: 'plugin', 149 pageObject: PluginsList, 150 pageObjectList: PluginsList.plugins, 151 async setup() { 152 server.createList('csi-plugin', PluginsList.pageSize, { shallow: true }); 153 await PluginsList.visit(); 154 }, 155 }); 156 });