open-vault/ui/tests/acceptance/secrets/backend/engines-test.js
Angel Garbarino 00e06301f1
Filter Secret Engine List view by engineType and/or name (#20481)
* initial WIP glimmerize the controller

* wip got the filter engine type by supported backends working

* got filter by engine type working

* wip need to refactor but working ish for name

* wip working state with both filters, does not work if both fiters are set

* fixed when you have two selected filters, but broken for multiples of the same type with different names

* remove repeated engineTypes in filter list

* add disabled to power select

* fix bug of glimmer for the concurrency task.

* wording fix

* remove linkableItem and the nested contextual compnents to help with loading speed.

* add changelog

* fix some tests

* add test coverage

* Update 20481.txt

update changelog text

* test fixes 🤞

* test fix?

* address a pr comment and save

* address pr comment
2023-05-15 16:57:27 +00:00

115 lines
4.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { currentRouteName, settled } from '@ember/test-helpers';
import { clickTrigger } from 'ember-power-select/test-support/helpers';
import { create } from 'ember-cli-page-object';
import { module, test } from 'qunit';
import { runCommands } from 'vault/tests/helpers/pki/pki-run-commands';
import { setupApplicationTest } from 'ember-qunit';
import { v4 as uuidv4 } from 'uuid';
import mountSecrets from 'vault/tests/pages/settings/mount-secret-backend';
import backendsPage from 'vault/tests/pages/secrets/backends';
import authPage from 'vault/tests/pages/auth';
import ss from 'vault/tests/pages/components/search-select';
const searchSelect = create(ss);
module('Acceptance | secret-engine list view', function (hooks) {
setupApplicationTest(hooks);
hooks.beforeEach(function () {
this.uid = uuidv4();
return authPage.login();
});
test('it allows you to disable an engine', async function (assert) {
// first mount an engine so we can disable it.
const enginePath = `alicloud-disable-${this.uid}`;
await mountSecrets.enable('alicloud', enginePath);
await settled();
assert.ok(backendsPage.rows.filterBy('path', `${enginePath}/`)[0], 'shows the mounted engine');
await backendsPage.visit();
await settled();
const row = backendsPage.rows.filterBy('path', `${enginePath}/`)[0];
await row.menu();
await settled();
await backendsPage.disableButton();
await settled();
await backendsPage.confirmDisable();
await settled();
assert.strictEqual(
currentRouteName(),
'vault.cluster.secrets.backends',
'redirects to the backends page'
);
assert.strictEqual(
backendsPage.rows.filterBy('path', `${enginePath}/`).length,
0,
'does not show the disabled engine'
);
});
test('it adds disabled css styling to unsupported secret engines', async function (assert) {
assert.expect(2);
// first mount engine that is not supported
const enginePath = `nomad-${this.uid}`;
await mountSecrets.enable('nomad', enginePath);
await settled();
await backendsPage.visit();
await settled();
const rows = document.querySelectorAll('[data-test-auth-backend-link]');
const rowUnsupported = Array.from(rows).filter((row) => row.innerText.includes('nomad'));
const rowSupported = Array.from(rows).filter((row) => row.innerText.includes('cubbyhole'));
assert
.dom(rowUnsupported[0])
.doesNotHaveClass(
'linked-block',
`the linked-block class is not added to unsupported engines, which effectively disables it.`
);
assert.dom(rowSupported[0]).hasClass('linked-block', `linked-block class is added to supported engines.`);
// cleanup
await runCommands([`delete sys/mounts/${enginePath}`]);
});
test('it filters by name and engine type', async function (assert) {
assert.expect(3);
const enginePath1 = `aws-1-${this.uid}`;
const enginePath2 = `aws-2-${this.uid}`;
await mountSecrets.enable('aws', enginePath1);
await mountSecrets.enable('aws', enginePath2);
await backendsPage.visit();
await settled();
// filter by type
await clickTrigger('#filter-by-engine-type');
await searchSelect.options.objectAt(0).click();
const rows = document.querySelectorAll('[data-test-auth-backend-link]');
const rowsAws = Array.from(rows).filter((row) => row.innerText.includes('aws'));
assert.strictEqual(rows.length, rowsAws.length, 'all rows returned are aws');
// filter by name
await clickTrigger('#filter-by-engine-name');
await searchSelect.options.objectAt(1).click();
const singleRow = document.querySelectorAll('[data-test-auth-backend-link]');
assert.dom(singleRow[0]).includesText('aws-2', 'shows the filtered by name engine');
// clear filter by engine name
await searchSelect.deleteButtons.objectAt(1).click();
const rowsAgain = document.querySelectorAll('[data-test-auth-backend-link]');
assert.ok(rowsAgain.length > 1, 'filter has been removed');
// cleanup
await runCommands([`delete sys/mounts/${enginePath1}`]);
await runCommands([`delete sys/mounts/${enginePath2}`]);
});
});