github.com/hernad/nomad@v1.6.112/ui/tests/acceptance/plugin-allocations-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 { module, test } from 'qunit'; 8 import { currentURL } from '@ember/test-helpers'; 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 PluginAllocations from 'nomad-ui/tests/pages/storage/plugins/plugin/allocations'; 14 15 module('Acceptance | plugin allocations', function (hooks) { 16 setupApplicationTest(hooks); 17 setupMirage(hooks); 18 19 let plugin; 20 21 hooks.beforeEach(function () { 22 server.create('node-pool'); 23 server.create('node'); 24 window.localStorage.clear(); 25 }); 26 27 test('it passes an accessibility audit', async function (assert) { 28 plugin = server.create('csi-plugin', { 29 shallow: true, 30 controllerRequired: true, 31 controllersExpected: 3, 32 nodesExpected: 3, 33 }); 34 35 await PluginAllocations.visit({ id: plugin.id }); 36 await a11yAudit(assert); 37 }); 38 39 test('/csi/plugins/:id/allocations shows all allocations in a single table', async function (assert) { 40 plugin = server.create('csi-plugin', { 41 shallow: true, 42 controllerRequired: true, 43 controllersExpected: 3, 44 nodesExpected: 3, 45 }); 46 47 await PluginAllocations.visit({ id: plugin.id }); 48 assert.equal(PluginAllocations.allocations.length, 6); 49 }); 50 51 pageSizeSelect({ 52 resourceName: 'allocation', 53 pageObject: PluginAllocations, 54 pageObjectList: PluginAllocations.allocations, 55 async setup() { 56 const total = PluginAllocations.pageSize; 57 plugin = server.create('csi-plugin', { 58 shallow: true, 59 controllerRequired: true, 60 controllersExpected: Math.floor(total / 2), 61 nodesExpected: Math.ceil(total / 2), 62 }); 63 64 await PluginAllocations.visit({ id: plugin.id }); 65 }, 66 }); 67 68 testFacet('Health', { 69 facet: PluginAllocations.facets.health, 70 paramName: 'healthy', 71 async beforeEach() { 72 plugin = server.create('csi-plugin', { 73 shallow: true, 74 controllerRequired: true, 75 controllersExpected: 3, 76 nodesExpected: 3, 77 }); 78 79 await PluginAllocations.visit({ id: plugin.id }); 80 }, 81 filter: (allocation, selection) => 82 selection.includes(allocation.healthy.toString()), 83 }); 84 85 testFacet('Type', { 86 facet: PluginAllocations.facets.type, 87 paramName: 'type', 88 async beforeEach() { 89 plugin = server.create('csi-plugin', { 90 shallow: true, 91 controllerRequired: true, 92 controllersExpected: 3, 93 nodesExpected: 3, 94 }); 95 96 await PluginAllocations.visit({ id: plugin.id }); 97 }, 98 filter: (allocation, selection) => { 99 if (selection.length === 0 || selection.length === 2) return true; 100 if (selection[0] === 'controller') 101 return plugin.controllers.models.includes(allocation); 102 return plugin.nodes.models.includes(allocation); 103 }, 104 }); 105 106 function testFacet(label, { facet, paramName, beforeEach, filter }) { 107 test(`the ${label} facet filters the allocations list by ${label}`, async function (assert) { 108 let option; 109 110 await beforeEach(); 111 await facet.toggle(); 112 113 option = facet.options.objectAt(0); 114 await option.toggle(); 115 116 const selection = [option.key]; 117 const allAllocations = [ 118 ...plugin.controllers.models, 119 ...plugin.nodes.models, 120 ]; 121 const expectedAllocations = allAllocations 122 .filter((allocation) => filter(allocation, selection)) 123 .sortBy('updateTime'); 124 125 PluginAllocations.allocations.forEach((allocation, index) => { 126 assert.equal(allocation.id, expectedAllocations[index].allocID); 127 }); 128 }); 129 130 test(`selecting multiple options in the ${label} facet results in a broader search`, async function (assert) { 131 const selection = []; 132 133 await beforeEach(); 134 await facet.toggle(); 135 136 const option1 = facet.options.objectAt(0); 137 const option2 = facet.options.objectAt(1); 138 await option1.toggle(); 139 selection.push(option1.key); 140 await option2.toggle(); 141 selection.push(option2.key); 142 143 const allAllocations = [ 144 ...plugin.controllers.models, 145 ...plugin.nodes.models, 146 ]; 147 const expectedAllocations = allAllocations 148 .filter((allocation) => filter(allocation, selection)) 149 .sortBy('updateTime'); 150 151 PluginAllocations.allocations.forEach((allocation, index) => { 152 assert.equal(allocation.id, expectedAllocations[index].allocID); 153 }); 154 }); 155 156 test(`selecting options in the ${label} facet updates the ${paramName} query param`, async function (assert) { 157 const selection = []; 158 159 await beforeEach(); 160 await facet.toggle(); 161 162 const option1 = facet.options.objectAt(0); 163 const option2 = facet.options.objectAt(1); 164 await option1.toggle(); 165 selection.push(option1.key); 166 await option2.toggle(); 167 selection.push(option2.key); 168 169 const queryString = `${paramName}=${window.encodeURIComponent( 170 JSON.stringify(selection) 171 )}`; 172 173 assert.equal( 174 currentURL(), 175 `/csi/plugins/${plugin.id}/allocations?${queryString}` 176 ); 177 }); 178 } 179 });