2020-04-04 02:25:33 +00:00
|
|
|
import { currentURL, visit } from '@ember/test-helpers';
|
|
|
|
import { module, test } from 'qunit';
|
2020-03-25 12:51:26 +00:00
|
|
|
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-04-04 16:58:34 +00:00
|
|
|
import pageSizeSelect from './behaviors/page-size-select';
|
2020-04-04 02:25:33 +00:00
|
|
|
import VolumesList from 'nomad-ui/tests/pages/storage/volumes/list';
|
2020-05-08 04:38:19 +00:00
|
|
|
import Layout from 'nomad-ui/tests/pages/layout';
|
2020-04-04 02:25:33 +00:00
|
|
|
|
|
|
|
const assignWriteAlloc = (volume, alloc) => {
|
|
|
|
volume.writeAllocs.add(alloc);
|
2020-11-25 21:44:06 +00:00
|
|
|
volume.allocations.add(alloc);
|
2020-04-04 02:25:33 +00:00
|
|
|
volume.save();
|
|
|
|
};
|
|
|
|
|
|
|
|
const assignReadAlloc = (volume, alloc) => {
|
|
|
|
volume.readAllocs.add(alloc);
|
2020-11-25 21:44:06 +00:00
|
|
|
volume.allocations.add(alloc);
|
2020-04-04 02:25:33 +00:00
|
|
|
volume.save();
|
|
|
|
};
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | volumes list', function (hooks) {
|
2020-03-25 12:51:26 +00:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2020-04-04 02:25:33 +00:00
|
|
|
server.create('node');
|
|
|
|
server.create('csi-plugin', { createVolumes: false });
|
2020-04-04 16:58:34 +00:00
|
|
|
window.localStorage.clear();
|
2020-04-04 02:25:33 +00:00
|
|
|
});
|
|
|
|
|
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
|
|
|
await VolumesList.visit();
|
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('visiting /csi redirects to /csi/volumes', async function (assert) {
|
2020-04-04 02:25:33 +00:00
|
|
|
await visit('/csi');
|
|
|
|
|
|
|
|
assert.equal(currentURL(), '/csi/volumes');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('visiting /csi/volumes', async function (assert) {
|
2020-04-04 02:25:33 +00:00
|
|
|
await VolumesList.visit();
|
|
|
|
|
|
|
|
assert.equal(currentURL(), '/csi/volumes');
|
|
|
|
assert.equal(document.title, 'CSI Volumes - Nomad');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/csi/volumes should list the first page of volumes sorted by name', async function (assert) {
|
2020-04-04 02:25:33 +00:00
|
|
|
const volumeCount = VolumesList.pageSize + 1;
|
|
|
|
server.createList('csi-volume', volumeCount);
|
|
|
|
|
|
|
|
await VolumesList.visit();
|
|
|
|
|
|
|
|
const sortedVolumes = server.db.csiVolumes.sortBy('id');
|
|
|
|
assert.equal(VolumesList.volumes.length, VolumesList.pageSize);
|
|
|
|
VolumesList.volumes.forEach((volume, index) => {
|
|
|
|
assert.equal(volume.name, sortedVolumes[index].id, 'Volumes are ordered');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('each volume row should contain information about the volume', async function (assert) {
|
2020-04-04 02:25:33 +00:00
|
|
|
const volume = server.create('csi-volume');
|
|
|
|
const readAllocs = server.createList('allocation', 2, { shallow: true });
|
|
|
|
const writeAllocs = server.createList('allocation', 3, { shallow: true });
|
2021-12-28 14:45:20 +00:00
|
|
|
readAllocs.forEach((alloc) => assignReadAlloc(volume, alloc));
|
|
|
|
writeAllocs.forEach((alloc) => assignWriteAlloc(volume, alloc));
|
2020-04-04 02:25:33 +00:00
|
|
|
|
|
|
|
await VolumesList.visit();
|
|
|
|
|
|
|
|
const volumeRow = VolumesList.volumes.objectAt(0);
|
|
|
|
|
2020-11-25 19:50:33 +00:00
|
|
|
let controllerHealthStr = 'Node Only';
|
|
|
|
if (volume.controllerRequired || volume.controllersExpected > 0) {
|
|
|
|
const healthy = volume.controllersHealthy;
|
|
|
|
const expected = volume.controllersExpected;
|
|
|
|
const isHealthy = healthy > 0;
|
2021-12-28 16:08:12 +00:00
|
|
|
controllerHealthStr = `${
|
|
|
|
isHealthy ? 'Healthy' : 'Unhealthy'
|
|
|
|
} (${healthy}/${expected})`;
|
2020-11-25 19:50:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-04 02:25:33 +00:00
|
|
|
const nodeHealthStr = volume.nodesHealthy > 0 ? 'Healthy' : 'Unhealthy';
|
|
|
|
|
|
|
|
assert.equal(volumeRow.name, volume.id);
|
2021-04-29 20:00:59 +00:00
|
|
|
assert.notOk(volumeRow.hasNamespace);
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
volumeRow.schedulable,
|
|
|
|
volume.schedulable ? 'Schedulable' : 'Unschedulable'
|
|
|
|
);
|
2020-11-25 19:50:33 +00:00
|
|
|
assert.equal(volumeRow.controllerHealth, controllerHealthStr);
|
2020-04-04 02:25:33 +00:00
|
|
|
assert.equal(
|
|
|
|
volumeRow.nodeHealth,
|
|
|
|
`${nodeHealthStr} (${volume.nodesHealthy}/${volume.nodesExpected})`
|
|
|
|
);
|
|
|
|
assert.equal(volumeRow.provider, volume.provider);
|
|
|
|
assert.equal(volumeRow.allocations, readAllocs.length + writeAllocs.length);
|
2020-03-25 12:51:26 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('each volume row should link to the corresponding volume', async function (assert) {
|
2021-04-29 20:00:59 +00:00
|
|
|
const [, secondNamespace] = server.createList('namespace', 2);
|
2021-12-28 16:08:12 +00:00
|
|
|
const volume = server.create('csi-volume', {
|
|
|
|
namespaceId: secondNamespace.id,
|
|
|
|
});
|
2020-04-04 02:25:33 +00:00
|
|
|
|
2021-04-29 20:00:59 +00:00
|
|
|
await VolumesList.visit({ namespace: '*' });
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-04-04 02:25:33 +00:00
|
|
|
await VolumesList.volumes.objectAt(0).clickName();
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/csi/volumes/${volume.id}?namespace=${secondNamespace.id}`
|
|
|
|
);
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2021-04-29 20:00:59 +00:00
|
|
|
await VolumesList.visit({ namespace: '*' });
|
|
|
|
assert.equal(currentURL(), '/csi/volumes?namespace=*');
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-04-04 02:25:33 +00:00
|
|
|
await VolumesList.volumes.objectAt(0).clickRow();
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/csi/volumes/${volume.id}?namespace=${secondNamespace.id}`
|
|
|
|
);
|
2020-04-04 02:25:33 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when there are no volumes, there is an empty message', async function (assert) {
|
2020-04-04 02:25:33 +00:00
|
|
|
await VolumesList.visit();
|
|
|
|
|
|
|
|
assert.ok(VolumesList.isEmpty);
|
|
|
|
assert.equal(VolumesList.emptyState.headline, 'No Volumes');
|
|
|
|
});
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when there are volumes, but no matches for a search, there is an empty message', async function (assert) {
|
2020-05-07 23:57:51 +00:00
|
|
|
server.create('csi-volume', { id: 'cat 1' });
|
|
|
|
server.create('csi-volume', { id: 'cat 2' });
|
|
|
|
|
|
|
|
await VolumesList.visit();
|
|
|
|
|
|
|
|
await VolumesList.search('dog');
|
|
|
|
assert.ok(VolumesList.isEmpty);
|
|
|
|
assert.equal(VolumesList.emptyState.headline, 'No Matches');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('searching resets the current page', async function (assert) {
|
2020-05-07 23:57:51 +00:00
|
|
|
server.createList('csi-volume', VolumesList.pageSize + 1);
|
|
|
|
|
|
|
|
await VolumesList.visit();
|
|
|
|
await VolumesList.nextPage();
|
|
|
|
|
|
|
|
assert.equal(currentURL(), '/csi/volumes?page=2');
|
|
|
|
|
|
|
|
await VolumesList.search('foobar');
|
|
|
|
|
|
|
|
assert.equal(currentURL(), '/csi/volumes?search=foobar');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the cluster has namespaces, each volume row includes the volume namespace', async function (assert) {
|
2021-04-29 20:00:59 +00:00
|
|
|
server.createList('namespace', 2);
|
|
|
|
const volume = server.create('csi-volume');
|
|
|
|
|
|
|
|
await VolumesList.visit({ namespace: '*' });
|
|
|
|
|
|
|
|
const volumeRow = VolumesList.volumes.objectAt(0);
|
|
|
|
assert.equal(volumeRow.namespace, volume.namespaceId);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the namespace query param is set, only matching volumes are shown and the namespace value is forwarded to app state', async function (assert) {
|
2020-04-04 02:25:33 +00:00
|
|
|
server.createList('namespace', 2);
|
2021-12-28 16:08:12 +00:00
|
|
|
const volume1 = server.create('csi-volume', {
|
|
|
|
namespaceId: server.db.namespaces[0].id,
|
|
|
|
});
|
|
|
|
const volume2 = server.create('csi-volume', {
|
|
|
|
namespaceId: server.db.namespaces[1].id,
|
|
|
|
});
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-04-04 02:25:33 +00:00
|
|
|
await VolumesList.visit();
|
2021-10-21 14:24:07 +00:00
|
|
|
assert.equal(VolumesList.volumes.length, 2);
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2021-10-21 14:24:07 +00:00
|
|
|
const firstNamespace = server.db.namespaces[0];
|
|
|
|
await VolumesList.visit({ namespace: firstNamespace.id });
|
2020-04-04 02:25:33 +00:00
|
|
|
assert.equal(VolumesList.volumes.length, 1);
|
|
|
|
assert.equal(VolumesList.volumes.objectAt(0).name, volume1.id);
|
|
|
|
|
|
|
|
const secondNamespace = server.db.namespaces[1];
|
|
|
|
await VolumesList.visit({ namespace: secondNamespace.id });
|
|
|
|
|
|
|
|
assert.equal(VolumesList.volumes.length, 1);
|
|
|
|
assert.equal(VolumesList.volumes.objectAt(0).name, volume2.id);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the active namespace is carried over to the jobs pages', async function (assert) {
|
2020-05-08 04:38:19 +00:00
|
|
|
server.createList('namespace', 2);
|
|
|
|
|
|
|
|
const namespace = server.db.namespaces[1];
|
2021-04-29 20:00:59 +00:00
|
|
|
await VolumesList.visit();
|
|
|
|
await VolumesList.facets.namespace.toggle();
|
|
|
|
await VolumesList.facets.namespace.options.objectAt(2).select();
|
2020-05-08 04:38:19 +00:00
|
|
|
|
|
|
|
await Layout.gutter.visitJobs();
|
|
|
|
|
|
|
|
assert.equal(currentURL(), `/jobs?namespace=${namespace.id}`);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when accessing volumes is forbidden, a message is shown with a link to the tokens page', async function (assert) {
|
2020-04-04 02:25:33 +00:00
|
|
|
server.pretender.get('/v1/volumes', () => [403, {}, null]);
|
|
|
|
|
|
|
|
await VolumesList.visit();
|
|
|
|
assert.equal(VolumesList.error.title, 'Not Authorized');
|
|
|
|
|
|
|
|
await VolumesList.error.seekHelp();
|
|
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
|
|
});
|
2020-04-04 16:58:34 +00:00
|
|
|
|
|
|
|
pageSizeSelect({
|
|
|
|
resourceName: 'volume',
|
|
|
|
pageObject: VolumesList,
|
|
|
|
pageObjectList: VolumesList.volumes,
|
|
|
|
async setup() {
|
|
|
|
server.createList('csi-volume', VolumesList.pageSize);
|
|
|
|
await VolumesList.visit();
|
|
|
|
},
|
|
|
|
});
|
2021-04-29 20:00:59 +00:00
|
|
|
|
|
|
|
testSingleSelectFacet('Namespace', {
|
|
|
|
facet: VolumesList.facets.namespace,
|
|
|
|
paramName: 'namespace',
|
|
|
|
expectedOptions: ['All (*)', 'default', 'namespace-2'],
|
|
|
|
optionToSelect: 'namespace-2',
|
|
|
|
async beforeEach() {
|
|
|
|
server.create('namespace', { id: 'default' });
|
|
|
|
server.create('namespace', { id: 'namespace-2' });
|
|
|
|
server.createList('csi-volume', 2, { namespaceId: 'default' });
|
|
|
|
server.createList('csi-volume', 2, { namespaceId: 'namespace-2' });
|
|
|
|
await VolumesList.visit();
|
|
|
|
},
|
|
|
|
filter(volume, selection) {
|
|
|
|
return volume.namespaceId === selection;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function testSingleSelectFacet(
|
|
|
|
label,
|
|
|
|
{ facet, paramName, beforeEach, filter, expectedOptions, optionToSelect }
|
|
|
|
) {
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`the ${label} facet has the correct options`, async function (assert) {
|
2021-04-29 20:00:59 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
let expectation;
|
|
|
|
if (typeof expectedOptions === 'function') {
|
|
|
|
expectation = expectedOptions(server.db.jobs);
|
|
|
|
} else {
|
|
|
|
expectation = expectedOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.deepEqual(
|
2021-12-28 14:45:20 +00:00
|
|
|
facet.options.map((option) => option.label.trim()),
|
2021-04-29 20:00:59 +00:00
|
|
|
expectation,
|
|
|
|
'Options for facet are as expected'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`the ${label} facet filters the volumes list by ${label}`, async function (assert) {
|
2021-04-29 20:00:59 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
const option = facet.options.findOneBy('label', optionToSelect);
|
|
|
|
const selection = option.key;
|
|
|
|
await option.select();
|
|
|
|
|
|
|
|
const expectedVolumes = server.db.csiVolumes
|
2021-12-28 14:45:20 +00:00
|
|
|
.filter((volume) => filter(volume, selection))
|
2021-04-29 20:00:59 +00:00
|
|
|
.sortBy('id');
|
|
|
|
|
|
|
|
VolumesList.volumes.forEach((volume, index) => {
|
|
|
|
assert.equal(
|
|
|
|
volume.name,
|
|
|
|
expectedVolumes[index].name,
|
|
|
|
`Volume at ${index} is ${expectedVolumes[index].name}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test(`selecting an option in the ${label} facet updates the ${paramName} query param`, async function (assert) {
|
2021-04-29 20:00:59 +00:00
|
|
|
await beforeEach();
|
|
|
|
await facet.toggle();
|
|
|
|
|
|
|
|
const option = facet.options.objectAt(1);
|
|
|
|
const selection = option.key;
|
|
|
|
await option.select();
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
currentURL().includes(`${paramName}=${selection}`),
|
|
|
|
'URL has the correct query param key and value'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2020-03-25 12:51:26 +00:00
|
|
|
});
|