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