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:
Lisbet Alvarez authored and Lisbet Alvarez committed 2024-07-15 17:23:00 -07:00
1 parent 3bcc5aabd8
commit c340d9ab89
17 files changed
+638 -135

No files matched your search

@@ -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();