2021-12-28 19:30:38 +00:00
|
|
|
/* eslint-disable qunit/require-expect */
|
2020-05-20 02:22:12 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { currentURL } from '@ember/test-helpers';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2020-07-28 17:59:14 +00:00
|
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
2020-05-20 02:22:12 +00:00
|
|
|
import pageSizeSelect from './behaviors/page-size-select';
|
|
|
|
import PluginAllocations from 'nomad-ui/tests/pages/storage/plugins/plugin/allocations';
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | plugin allocations', function (hooks) {
|
2020-05-20 02:22:12 +00:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
let plugin;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2020-05-20 02:22:12 +00:00
|
|
|
server.create('node');
|
|
|
|
window.localStorage.clear();
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
2020-07-28 17:59:14 +00:00
|
|
|
plugin = server.create('csi-plugin', {
|
|
|
|
shallow: true,
|
|
|
|
controllerRequired: true,
|
|
|
|
controllersExpected: 3,
|
|
|
|
nodesExpected: 3,
|
|
|
|
});
|
|
|
|
|
|
|
|
await PluginAllocations.visit({ id: plugin.id });
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/csi/plugins/:id/allocations shows all allocations in a single table', async function (assert) {
|
2020-05-20 02:22:12 +00:00
|
|
|
plugin = server.create('csi-plugin', {
|
|
|
|
shallow: true,
|
|
|
|
controllerRequired: true,
|
|
|
|
controllersExpected: 3,
|
|
|
|
nodesExpected: 3,
|
|
|
|
});
|
|
|
|
|
|
|
|
await PluginAllocations.visit({ id: plugin.id });
|
|
|
|
assert.equal(PluginAllocations.allocations.length, 6);
|
|
|
|
});
|
|
|
|
|
|
|
|
pageSizeSelect({
|
|
|
|
resourceName: 'allocation',
|
|
|
|
pageObject: PluginAllocations,
|
|
|
|
pageObjectList: PluginAllocations.allocations,
|
|
|
|
async setup() {
|
|
|
|
const total = PluginAllocations.pageSize;
|
|
|
|
plugin = server.create('csi-plugin', {
|
|
|
|
shallow: true,
|
|
|
|
controllerRequired: true,
|
|
|
|
controllersExpected: Math.floor(total / 2),
|
|
|
|
nodesExpected: Math.ceil(total / 2),
|
|
|
|
});
|
|
|
|
|
|
|
|
await PluginAllocations.visit({ id: plugin.id });
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
testFacet('Health', {
|
|
|
|
facet: PluginAllocations.facets.health,
|
|
|
|
paramName: 'healthy',
|
|
|
|
async beforeEach() {
|
|
|
|
plugin = server.create('csi-plugin', {
|
|
|
|
shallow: true,
|
|
|
|
controllerRequired: true,
|
|
|
|
controllersExpected: 3,
|
|
|
|
nodesExpected: 3,
|
|
|
|
});
|
|
|
|
|
|
|
|
await PluginAllocations.visit({ id: plugin.id });
|
|
|
|
},
|
2021-12-28 16:08:12 +00:00
|
|
|
filter: (allocation, selection) =>
|
|
|
|
selection.includes(allocation.healthy.toString()),
|
2020-05-20 02:22:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testFacet('Type', {
|
|
|
|
facet: PluginAllocations.facets.type,
|
|
|
|
paramName: 'type',
|
|
|
|
async beforeEach() {
|
|
|
|
plugin = server.create('csi-plugin', {
|
|
|
|
shallow: true,
|
|
|
|
controllerRequired: true,
|
|
|
|
controllersExpected: 3,
|
|
|
|
nodesExpected: 3,
|
|
|
|
});
|
|
|
|
|
|
|
|
await PluginAllocations.visit({ id: plugin.id });
|
|
|
|
},
|
|
|
|
filter: (allocation, selection) => {
|
|
|
|
if (selection.length === 0 || selection.length === 2) return true;
|
2021-12-28 16:08:12 +00:00
|
|
|
if (selection[0] === 'controller')
|
|
|
|
return plugin.controllers.models.includes(allocation);
|
2020-05-20 02:22:12 +00:00
|
|
|
return plugin.nodes.models.includes(allocation);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function testFacet(label, { facet, paramName, beforeEach, filter }) {
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`the ${label} facet filters the allocations list by ${label}`, async function (assert) {
|
2020-05-20 02:22:12 +00:00
|
|
|
let option;
|
|
|
|
|
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
option = facet.options.objectAt(0);
|
|
|
|
await option.toggle();
|
|
|
|
|
|
|
|
const selection = [option.key];
|
2021-12-28 16:08:12 +00:00
|
|
|
const allAllocations = [
|
|
|
|
...plugin.controllers.models,
|
|
|
|
...plugin.nodes.models,
|
|
|
|
];
|
2020-05-20 02:22:12 +00:00
|
|
|
const expectedAllocations = allAllocations
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((allocation) => filter(allocation, selection))
|
2020-05-20 02:22:12 +00:00
|
|
|
.sortBy('updateTime');
|
|
|
|
|
|
|
|
PluginAllocations.allocations.forEach((allocation, index) => {
|
|
|
|
assert.equal(allocation.id, expectedAllocations[index].allocID);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`selecting multiple options in the ${label} facet results in a broader search`, async function (assert) {
|
2020-05-20 02:22:12 +00:00
|
|
|
const selection = [];
|
|
|
|
|
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
const option1 = facet.options.objectAt(0);
|
|
|
|
const option2 = facet.options.objectAt(1);
|
|
|
|
await option1.toggle();
|
|
|
|
selection.push(option1.key);
|
|
|
|
await option2.toggle();
|
|
|
|
selection.push(option2.key);
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
const allAllocations = [
|
|
|
|
...plugin.controllers.models,
|
|
|
|
...plugin.nodes.models,
|
|
|
|
];
|
2020-05-20 02:22:12 +00:00
|
|
|
const expectedAllocations = allAllocations
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((allocation) => filter(allocation, selection))
|
2020-05-20 02:22:12 +00:00
|
|
|
.sortBy('updateTime');
|
|
|
|
|
|
|
|
PluginAllocations.allocations.forEach((allocation, index) => {
|
|
|
|
assert.equal(allocation.id, expectedAllocations[index].allocID);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`selecting options in the ${label} facet updates the ${paramName} query param`, async function (assert) {
|
2020-05-20 02:22:12 +00:00
|
|
|
const selection = [];
|
|
|
|
|
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
const option1 = facet.options.objectAt(0);
|
|
|
|
const option2 = facet.options.objectAt(1);
|
|
|
|
await option1.toggle();
|
|
|
|
selection.push(option1.key);
|
|
|
|
await option2.toggle();
|
|
|
|
selection.push(option2.key);
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
const queryString = `${paramName}=${window.encodeURIComponent(
|
|
|
|
JSON.stringify(selection)
|
|
|
|
)}`;
|
2020-05-20 02:22:12 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/csi/plugins/${plugin.id}/allocations?${queryString}`
|
|
|
|
);
|
2020-05-20 02:22:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|