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