feat: 🎸 add search and filtering to scopes tab in a role (#2371)
* feat: 🎸 add search and filtering to scopes tab in a role ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13886
This commit is contained in:
1 parent
3bcc5aabd8
commit
c340d9ab89
17 files changed
+638
-135
No files matched your search
@@ -22,6 +22,7 @@ import {
|
||||
GRANT_SCOPE_CHILDREN,
|
||||
GRANT_SCOPE_DESCENDANTS,
|
||||
} from 'api/models/role';
|
||||
import { TYPE_SCOPE_ORG } from 'api/models/scope';
|
||||
|
||||
module('Acceptance | roles | global-scope', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
@@ -32,6 +33,12 @@ module('Acceptance | roles | global-scope', function (hooks) {
|
||||
`.hds-form-toggle input[name="${name}"]`;
|
||||
const SCOPE_CHECKBOX_SELECTOR = (type, id) =>
|
||||
`tbody [data-test-${type}-scopes-table-row="${id}"] input`;
|
||||
const GRANT_SCOPE_ROW_SELECTOR = (id) =>
|
||||
`tbody [data-test-grant-scope-row="${id}"]`;
|
||||
const FILTER_DROPDOWN_SELECTOR = (name) =>
|
||||
`.search-filtering [name="${name}"] button`;
|
||||
const FILTER_APPLY_BUTTON_SELECTOR =
|
||||
'.search-filtering [data-test-dropdown-apply-button]';
|
||||
const TABLE_ROW_SELECTOR = 'tbody tr';
|
||||
const TABLE_SCOPE_SELECTOR = 'tbody tr:nth-child(2) a';
|
||||
const TABLE_PARENT_SCOPE_SELECTOR = 'tbody tr:nth-child(2) td:nth-child(3) a';
|
||||
@@ -45,6 +52,8 @@ module('Acceptance | roles | global-scope', function (hooks) {
|
||||
const NO_SCOPES_MSG_SELECTOR = '.role-grant-scopes div';
|
||||
const NO_SCOPES_MSG_LINK_SELECTOR =
|
||||
'.role-grant-scopes div div:nth-child(3) a';
|
||||
const BUTTON_ICON_SELECTOR =
|
||||
'.hds-button__icon [data-test-icon="check-circle"]';
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -109,10 +118,109 @@ module('Acceptance | roles | global-scope', function (hooks) {
|
||||
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
`/scopes/${instances.scopes.global.id}/scopes`,
|
||||
`/scopes/${instances.role.grant_scope_ids[1]}/scopes`,
|
||||
);
|
||||
});
|
||||
|
||||
test('user can search for existing grant scope on a role', async function (assert) {
|
||||
await visit(urls.role);
|
||||
|
||||
await click(`[href="${urls.roleScopes}"]`);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.exists();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.exists();
|
||||
|
||||
await fillIn(SEARCH_INPUT_SELECTOR, instances.role.grant_scope_ids[0]);
|
||||
await waitUntil(
|
||||
() =>
|
||||
findAll(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.length === 0,
|
||||
);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.exists();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.doesNotExist();
|
||||
});
|
||||
|
||||
test('user can search for grant scopes on a role and get no results', async function (assert) {
|
||||
await visit(urls.role);
|
||||
|
||||
await click(`[href="${urls.roleScopes}"]`);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.exists();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.exists();
|
||||
|
||||
await fillIn(SEARCH_INPUT_SELECTOR, 'fake scope that does not exist');
|
||||
await waitUntil(() => findAll(NO_RESULTS_MSG_SELECTOR).length === 1);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.doesNotExist();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.doesNotExist();
|
||||
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
|
||||
});
|
||||
|
||||
test('user can filter for grant scopes on a role by parent scope', async function (assert) {
|
||||
await visit(urls.role);
|
||||
|
||||
await click(`[href="${urls.roleScopes}"]`);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.exists();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.exists();
|
||||
|
||||
await click(FILTER_DROPDOWN_SELECTOR('parent-scope'));
|
||||
await click(`input[value="${instances.scopes.global.id}"]`);
|
||||
await click(FILTER_APPLY_BUTTON_SELECTOR);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.doesNotExist();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.exists();
|
||||
});
|
||||
|
||||
test('user can filter for grant scopes on a role by type', async function (assert) {
|
||||
await visit(urls.role);
|
||||
|
||||
await click(`[href="${urls.roleScopes}"]`);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.exists();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.exists();
|
||||
|
||||
await click(FILTER_DROPDOWN_SELECTOR('type'));
|
||||
await click(`input[value="${TYPE_SCOPE_ORG}"]`);
|
||||
await click(FILTER_APPLY_BUTTON_SELECTOR);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.doesNotExist();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.exists();
|
||||
});
|
||||
|
||||
test('user can naviage to parent scope from role grant scopes', async function (assert) {
|
||||
instances.role.update({
|
||||
grant_scope_ids: ['this', instances.scopes.org.id],
|
||||
@@ -260,6 +368,7 @@ module('Acceptance | roles | global-scope', function (hooks) {
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.manageScopes);
|
||||
assert.dom(BUTTON_ICON_SELECTOR).isVisible();
|
||||
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
|
||||
@@ -403,6 +512,7 @@ module('Acceptance | roles | global-scope', function (hooks) {
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.manageScopes);
|
||||
assert.dom(BUTTON_ICON_SELECTOR).isVisible();
|
||||
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ module('Acceptance | roles | org-scope', function (hooks) {
|
||||
`.hds-form-toggle input[name="${name}"]`;
|
||||
const SCOPE_CHECKBOX_SELECTOR = (type, id) =>
|
||||
`tbody [data-test-${type}-scopes-table-row="${id}"] input`;
|
||||
const GRANT_SCOPE_ROW_SELECTOR = (id) =>
|
||||
`tbody [data-test-grant-scope-row="${id}"]`;
|
||||
const FILTER_DROPDOWN_SELECTOR = (name) =>
|
||||
`.search-filtering [name="${name}"] button`;
|
||||
const TABLE_ROW_SELECTOR = 'tbody tr';
|
||||
const TABLE_SCOPE_SELECTOR = 'tbody tr:nth-child(2) a';
|
||||
const TABLE_PARENT_SCOPE_SELECTOR = 'tbody tr:nth-child(2) td:nth-child(3) a';
|
||||
@@ -45,6 +49,8 @@ module('Acceptance | roles | org-scope', function (hooks) {
|
||||
const NO_SCOPES_MSG_SELECTOR = '.role-grant-scopes div';
|
||||
const NO_SCOPES_MSG_LINK_SELECTOR =
|
||||
'.role-grant-scopes div div:nth-child(3) a';
|
||||
const BUTTON_ICON_SELECTOR =
|
||||
'.hds-button__icon [data-test-icon="check-circle"]';
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -109,7 +115,7 @@ module('Acceptance | roles | org-scope', function (hooks) {
|
||||
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
`/scopes/${instances.scopes.org.id}/scopes`,
|
||||
`/scopes/${instances.role.grant_scope_ids[1]}/edit`,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -121,10 +127,70 @@ module('Acceptance | roles | org-scope', function (hooks) {
|
||||
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
`/scopes/${instances.scopes.global.id}/scopes`,
|
||||
`/scopes/${instances.scopes.org.id}/scopes`,
|
||||
);
|
||||
});
|
||||
|
||||
test('user can search for existing grant scope on a role', async function (assert) {
|
||||
await visit(urls.role);
|
||||
|
||||
await click(`[href="${urls.roleScopes}"]`);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.exists();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.exists();
|
||||
|
||||
await fillIn(SEARCH_INPUT_SELECTOR, instances.role.grant_scope_ids[0]);
|
||||
await waitUntil(
|
||||
() =>
|
||||
findAll(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.length === 0,
|
||||
);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.exists();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.doesNotExist();
|
||||
});
|
||||
|
||||
test('user can search for grant scopes on a role and get no results', async function (assert) {
|
||||
await visit(urls.role);
|
||||
|
||||
await click(`[href="${urls.roleScopes}"]`);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.exists();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.exists();
|
||||
|
||||
await fillIn(SEARCH_INPUT_SELECTOR, 'fake scope that does not exist');
|
||||
await waitUntil(() => findAll(NO_RESULTS_MSG_SELECTOR).length === 1);
|
||||
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[0]))
|
||||
.doesNotExist();
|
||||
assert
|
||||
.dom(GRANT_SCOPE_ROW_SELECTOR(instances.role.grant_scope_ids[1]))
|
||||
.doesNotExist();
|
||||
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
|
||||
});
|
||||
|
||||
test('user cannot filter grant scopes on an org level role', async function (assert) {
|
||||
await visit(urls.role);
|
||||
|
||||
await click(`[href="${urls.roleScopes}"]`);
|
||||
|
||||
assert.dom(FILTER_DROPDOWN_SELECTOR('parent-scope')).doesNotExist();
|
||||
assert.dom(FILTER_DROPDOWN_SELECTOR('type')).doesNotExist();
|
||||
});
|
||||
|
||||
test('user sees no scopes message and action when role has no grant scopes', async function (assert) {
|
||||
instances.role.update({ grant_scope_ids: [] });
|
||||
await visit(urls.role);
|
||||
@@ -258,6 +324,7 @@ module('Acceptance | roles | org-scope', function (hooks) {
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.manageScopes);
|
||||
assert.dom(BUTTON_ICON_SELECTOR).isVisible();
|
||||
|
||||
await click(SAVE_BTN_SELECTOR);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { visit, currentURL } from '@ember/test-helpers';
|
||||
import { visit, currentURL, waitUntil } from '@ember/test-helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
|
||||
@@ -67,7 +67,8 @@ module(
|
||||
test('cancel action causes transition to expected route', async function (assert) {
|
||||
await visit(urls.manageScopes);
|
||||
|
||||
await controller.cancel();
|
||||
controller.cancel();
|
||||
await waitUntil(() => currentURL() === urls.scopes);
|
||||
|
||||
assert.strictEqual(currentURL(), urls.scopes);
|
||||
});
|
||||
|
||||
@@ -4,18 +4,22 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { visit, waitUntil } from '@ember/test-helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import {
|
||||
GRANT_SCOPE_THIS,
|
||||
GRANT_SCOPE_CHILDREN,
|
||||
GRANT_SCOPE_DESCENDANTS,
|
||||
} from 'api/models/role';
|
||||
import { TYPE_SCOPE_ORG, TYPE_SCOPE_PROJECT } from 'api/models/scope';
|
||||
|
||||
module('Unit | Controller | scopes/scope/roles/role/scopes', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
let controller;
|
||||
|
||||
@@ -60,4 +64,48 @@ module('Unit | Controller | scopes/scope/roles/role/scopes', function (hooks) {
|
||||
);
|
||||
assert.notOk(controller.isKeywordChildrenOrDescendants(GRANT_SCOPE_THIS));
|
||||
});
|
||||
|
||||
test('availableParentScopes returns expected object', async function (assert) {
|
||||
instances.scopes.org = this.server.create('scope', {
|
||||
type: 'org',
|
||||
scope: { id: instances.scopes.global.id },
|
||||
});
|
||||
instances.role.update({ grant_scope_ids: [instances.scopes.org.id] });
|
||||
await visit(urls.scopes);
|
||||
|
||||
assert.deepEqual(controller.availableParentScopes, [
|
||||
{ id: instances.scopes.global.id },
|
||||
]);
|
||||
});
|
||||
|
||||
test('scopeTypeOptions returns expected object', function (assert) {
|
||||
assert.deepEqual(controller.scopeTypeOptions, [
|
||||
{ id: TYPE_SCOPE_ORG, name: 'Org' },
|
||||
{ id: TYPE_SCOPE_PROJECT, name: 'Project' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('filters returns expected entries', async function (assert) {
|
||||
await visit(urls.scopes);
|
||||
|
||||
assert.ok(controller.filters.allFilters);
|
||||
assert.ok(controller.filters.selectedFilters);
|
||||
});
|
||||
|
||||
test('handleSearchInput action sets expected values correctly', async function (assert) {
|
||||
const searchValue = 'test';
|
||||
controller.handleSearchInput({ target: { value: searchValue } });
|
||||
await waitUntil(() => controller.search === searchValue);
|
||||
|
||||
assert.strictEqual(controller.page, 1);
|
||||
assert.strictEqual(controller.search, searchValue);
|
||||
});
|
||||
|
||||
test('applyFilter action sets expected values correctly', function (assert) {
|
||||
const selectedItems = [TYPE_SCOPE_ORG];
|
||||
controller.applyFilter('types', selectedItems);
|
||||
|
||||
assert.strictEqual(controller.page, 1);
|
||||
assert.deepEqual(controller.types, selectedItems);
|
||||
});
|
||||
});
|
||||
@@ -36,6 +36,7 @@ module('Unit | Controller | scopes/scope/targets/index', function (hooks) {
|
||||
const urls = {
|
||||
projectScope: null,
|
||||
targets: null,
|
||||
target: null,
|
||||
alias: null,
|
||||
};
|
||||
|
||||
@@ -68,7 +69,8 @@ module('Unit | Controller | scopes/scope/targets/index', function (hooks) {
|
||||
|
||||
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
|
||||
urls.targets = `${urls.projectScope}/targets`;
|
||||
urls.alias = `${urls.projectScope}/targets/${instances.target.id}/${instances.alias.id}`;
|
||||
urls.target = `${urls.targets}/${instances.target.id}`;
|
||||
urls.alias = `${urls.target}/${instances.alias.id}`;
|
||||
|
||||
getTargetCount = () => this.server.schema.targets.all().models.length;
|
||||
getAliasCount = () => this.server.schema.aliases.all().models.length;
|
||||
@@ -218,7 +220,7 @@ module('Unit | Controller | scopes/scope/targets/index', function (hooks) {
|
||||
});
|
||||
|
||||
test('deleteAlias action destroys specified model', async function (assert) {
|
||||
await visit(urls.targets);
|
||||
await visit(urls.target);
|
||||
const alias = await store.findRecord('alias', instances.alias.id);
|
||||
const aliasCount = getAliasCount();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | scopes/scope/roles/role/scopes', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
Reference in new issue
Block a user