Icu 12590 add filtering pagination support for roles (#2204)
* feat: 🎸 add search & pagination for roles ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12590
This commit is contained in:
1 parent
a78522e09a
commit
8be4e93a3c
14 files changed
+328
-117
No files matched your search
@@ -7,6 +7,7 @@ import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import { Response } from 'miragejs';
|
||||
import {
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
module('Acceptance | roles | create', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { visit, find } from '@ember/test-helpers';
|
||||
import { visit, findAll, click, fillIn, waitUntil } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import {
|
||||
authenticateSession,
|
||||
// These are left here intentionally for future reference.
|
||||
@@ -17,19 +18,26 @@ import {
|
||||
module('Acceptance | roles | list', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
const SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]';
|
||||
const NO_RESULTS_MSG_SELECTOR = '[data-test-no-role-results]';
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
global: null,
|
||||
org: null,
|
||||
},
|
||||
role1: null,
|
||||
role2: null,
|
||||
};
|
||||
|
||||
const urls = {
|
||||
scopes: {
|
||||
org: null,
|
||||
},
|
||||
globalScope: null,
|
||||
orgScope: null,
|
||||
roles: null,
|
||||
role1: null,
|
||||
role2: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
@@ -38,35 +46,80 @@ module('Acceptance | roles | list', function (hooks) {
|
||||
type: 'org',
|
||||
scope: { id: 'global', type: 'global' },
|
||||
});
|
||||
instances.role = this.server.create('role', {
|
||||
instances.role1 = this.server.create('role', {
|
||||
scope: instances.scopes.org,
|
||||
});
|
||||
urls.scopes.org = `/scopes/${instances.scopes.org.id}`;
|
||||
|
||||
instances.role2 = this.server.create('role', {
|
||||
scope: instances.scopes.org,
|
||||
});
|
||||
urls.globalScope = `/scopes/global/scopes`;
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
|
||||
urls.roles = `/scopes/${instances.scopes.org.id}/roles`;
|
||||
urls.role1 = `${urls.roles}/${instances.role1.id}`;
|
||||
urls.role2 = `${urls.roles}/${instances.role2.id}`;
|
||||
authenticateSession({});
|
||||
});
|
||||
|
||||
test('Users can navigate to roles with proper authorization', async function (assert) {
|
||||
await visit(urls.scopes.org);
|
||||
assert.ok(
|
||||
test('users can navigate to roles with proper authorization', async function (assert) {
|
||||
await visit(urls.globalScope);
|
||||
|
||||
await click(`[href="${urls.orgScope}"]`);
|
||||
|
||||
assert.true(
|
||||
instances.scopes.org.authorized_collection_actions.roles.includes('list'),
|
||||
);
|
||||
assert.ok(find(`[href="${urls.roles}"]`));
|
||||
assert.dom(`[href="${urls.roles}"]`).exists();
|
||||
});
|
||||
|
||||
test('Users cannot navigate to index without either list or create actions', async function (assert) {
|
||||
test('users cannot navigate to index without either list or create actions', async function (assert) {
|
||||
instances.scopes.org.authorized_collection_actions.roles = [];
|
||||
await visit(urls.scopes.org);
|
||||
assert.notOk(
|
||||
await visit(urls.globalScope);
|
||||
|
||||
await click(`[href="${urls.orgScope}"]`);
|
||||
|
||||
assert.false(
|
||||
instances.scopes.org.authorized_collection_actions.roles.includes('list'),
|
||||
);
|
||||
assert.notOk(find(`[href="${urls.roles}"]`));
|
||||
assert.dom(`[href="${urls.roles}"]`).doesNotExist();
|
||||
});
|
||||
|
||||
test('Users can navigate to index with only create action', async function (assert) {
|
||||
test('users can navigate to index with only create action', async function (assert) {
|
||||
instances.scopes.org.authorized_collection_actions.roles = ['create'];
|
||||
await visit(urls.scopes.org);
|
||||
assert.ok(find(`[href="${urls.roles}"]`));
|
||||
await visit(urls.globalScope);
|
||||
|
||||
await click(`[href="${urls.orgScope}"]`);
|
||||
|
||||
assert.dom(`[href="${urls.roles}"]`).exists();
|
||||
});
|
||||
|
||||
test('user can search for a specifc role by id', async function (assert) {
|
||||
await visit(urls.orgScope);
|
||||
|
||||
await click(`[href="${urls.roles}"]`);
|
||||
|
||||
assert.dom(`[href="${urls.role1}"]`).exists();
|
||||
assert.dom(`[href="${urls.role2}"]`).exists();
|
||||
|
||||
await fillIn(SEARCH_INPUT_SELECTOR, instances.role1.id);
|
||||
await waitUntil(() => findAll(`[href="${urls.role2}"]`).length === 0);
|
||||
|
||||
assert.dom(`[href="${urls.role1}"]`).exists();
|
||||
assert.dom(`[href="${urls.role2}"]`).doesNotExist();
|
||||
});
|
||||
|
||||
test('user can search for roles and get no results', async function (assert) {
|
||||
await visit(urls.orgScope);
|
||||
|
||||
await click(`[href="${urls.roles}"]`);
|
||||
|
||||
assert.dom(`[href="${urls.role1}"]`).exists();
|
||||
assert.dom(`[href="${urls.role2}"]`).exists();
|
||||
|
||||
await fillIn(SEARCH_INPUT_SELECTOR, 'fake role that does not exist');
|
||||
await waitUntil(() => findAll(NO_RESULTS_MSG_SELECTOR).length === 1);
|
||||
|
||||
assert.dom(`[href="${urls.role1}"]`).doesNotExist();
|
||||
assert.dom(`[href="${urls.role2}"]`).doesNotExist();
|
||||
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
|
||||
});
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import { module, test } from 'qunit';
|
||||
import { visit, currentURL, click, find } from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import a11yAudit from 'ember-a11y-testing/test-support/audit';
|
||||
import {
|
||||
authenticateSession,
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
module('Acceptance | roles | read', function (hooks) {
|
||||
setupApplicationTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
const instances = {
|
||||
scopes: {
|
||||
@@ -55,7 +57,8 @@ module('Acceptance | roles | read', function (hooks) {
|
||||
},
|
||||
'withPrincipals',
|
||||
);
|
||||
urls.roles = `/scopes/${instances.scopes.org.id}/roles`;
|
||||
urls.orgScope = `/scopes/${instances.scopes.org.id}`;
|
||||
urls.roles = `${urls.orgScope}/roles`;
|
||||
urls.role = `${urls.roles}/${instances.role.id}`;
|
||||
urls.newRole = `${urls.roles}/new`;
|
||||
});
|
||||
@@ -67,7 +70,10 @@ module('Acceptance | roles | read', function (hooks) {
|
||||
});
|
||||
|
||||
test('can navigate to a role form', async function (assert) {
|
||||
await visit(urls.roles);
|
||||
await visit(urls.orgScope);
|
||||
|
||||
await click(`[href="${urls.roles}"]`);
|
||||
|
||||
await click('main tbody .hds-table__tr:nth-child(1) a');
|
||||
await a11yAudit();
|
||||
assert.strictEqual(currentURL(), urls.role);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { waitUntil } from '@ember/test-helpers';
|
||||
|
||||
module('Unit | Controller | scopes/scope/roles/index', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup('controller:scopes/scope/roles/index');
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('handleSearchInput action sets expected values correctly', async function (assert) {
|
||||
let controller = this.owner.lookup('controller:scopes/scope/roles/index');
|
||||
const searchValue = 'test';
|
||||
controller.handleSearchInput({ target: { value: searchValue } });
|
||||
await waitUntil(() => controller.search === searchValue);
|
||||
|
||||
assert.strictEqual(controller.page, 1);
|
||||
assert.strictEqual(controller.search, searchValue);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user