Icu 16413 roles principals (#2835)

* test: 💍 add selectors to roles principals

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16413

* test: 💍 add selectors for roles project scope

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16413

* change exists() to isVisible()
This commit is contained in:
Cameron Perera authored and GitHub committed 2025-05-20 17:08:08 -05:00
1 parent c445f95aa4
commit 1ef7d9b5a7
3 files changed
+81 -56

No files matched your search

@@ -4,13 +4,14 @@
*/
import { module, test } from 'qunit';
import { visit, currentURL, click, find, findAll } from '@ember/test-helpers';
import { visit, currentURL, click, findAll } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
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 { authenticateSession } from 'ember-simple-auth/test-support';
import * as selectors from './selectors';
import * as commonSelectors from 'admin/tests/helpers/selectors';
module('Acceptance | roles | principals', function (hooks) {
@@ -18,9 +19,6 @@ module('Acceptance | roles | principals', function (hooks) {
setupMirage(hooks);
setupIndexedDb(hooks);
const MANAGE_DROPDOWN_SELECTOR = '[data-test-manage-roles-dropdown] button';
const ADD_PRINCIPALS_SELECTOR = '[data-test-manage-role-principals]';
const instances = {
scopes: {
global: null,
@@ -63,16 +61,22 @@ module('Acceptance | roles | principals', function (hooks) {
test('visiting role principals', async function (assert) {
await visit(urls.rolePrincipals);
await a11yAudit();
assert.strictEqual(currentURL(), urls.rolePrincipals);
assert.strictEqual(findAll('tbody tr').length, principalsCount);
});
test('principal can be removed from a role', async function (assert) {
await visit(urls.rolePrincipals);
assert.strictEqual(findAll('tbody tr').length, principalsCount);
await click('tbody tr td:last-child .hds-dropdown-toggle-icon');
await click('tbody tr .hds-dropdown-list-item button');
assert.strictEqual(findAll('tbody tr').length, principalsCount - 1);
assert.dom(commonSelectors.TABLE_ROW).exists({ count: principalsCount });
await click(commonSelectors.TABLE_FIRST_ROW_ACTION_DROPDOWN);
await click(commonSelectors.TABLE_FIRST_ROW_ACTION_DROPDOWN_ITEM_BTN);
assert
.dom(commonSelectors.TABLE_ROW)
.exists({ count: principalsCount - 1 });
});
test('principal cannot be removed from a role without proper authorization', async function (assert) {
@@ -80,8 +84,10 @@ module('Acceptance | roles | principals', function (hooks) {
(item) => item !== 'remove-principals',
);
instances.role.update({ authorized_actions });
await visit(urls.rolePrincipals);
assert.notOk(find('tbody tr .hds-dropdown-list-item button'));
assert.dom(commonSelectors.TABLE_FIRST_ROW_ACTION_DROPDOWN).doesNotExist();
});
test('shows error message on principal remove', async function (assert) {
@@ -98,9 +104,12 @@ module('Acceptance | roles | principals', function (hooks) {
);
});
await visit(urls.rolePrincipals);
assert.strictEqual(findAll('tbody tr').length, principalsCount);
await click('tbody tr td:last-child .hds-dropdown-toggle-icon');
await click('tbody tr .hds-dropdown-list-item button');
assert.dom(commonSelectors.TABLE_ROW).exists({ count: principalsCount });
await click(commonSelectors.TABLE_FIRST_ROW_ACTION_DROPDOWN);
await click(commonSelectors.TABLE_FIRST_ROW_ACTION_DROPDOWN_ITEM_BTN);
assert
.dom(commonSelectors.ALERT_TOAST_BODY)
.hasText('The request was invalid.');
@@ -111,40 +120,59 @@ module('Acceptance | roles | principals', function (hooks) {
(item) => item !== 'add-principals',
);
instances.role.update({ authorized_actions });
await visit(urls.rolePrincipals);
assert.dom(ADD_PRINCIPALS_SELECTOR).doesNotExist();
await click(selectors.MANAGE_DROPDOWN_ROLES);
assert.dom(selectors.MANAGE_DROPDOWN_ADD_PRINCIPALS).doesNotExist();
});
test('select and save principals to add', async function (assert) {
instances.role.update({ userIds: [], groupIds: [], managedGroupIds: [] });
await visit(urls.rolePrincipals);
assert.strictEqual(findAll('tbody tr').length, 0);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(ADD_PRINCIPALS_SELECTOR);
assert.dom(commonSelectors.TABLE_ROW).exists({ count: 0 });
await click(selectors.MANAGE_DROPDOWN_ROLES);
await click(selectors.MANAGE_DROPDOWN_ADD_PRINCIPALS);
assert.strictEqual(currentURL(), urls.addPrincipals);
// Click three times to select, unselect, then reselect (for coverage)
await click('tbody label');
await click('tbody label');
await click('tbody label');
await click('form [type="submit"]');
await click(commonSelectors.TABLE_ROW_CHECKBOX);
await click(commonSelectors.TABLE_ROW_CHECKBOX);
await click(commonSelectors.TABLE_ROW_CHECKBOX);
await click(commonSelectors.SAVE_BTN);
await visit(urls.rolePrincipals);
assert.strictEqual(findAll('tbody tr').length, 1);
assert.dom(commonSelectors.TABLE_ROW).exists({ count: 1 });
});
test('select and cancel principals to add', async function (assert) {
await visit(urls.rolePrincipals);
assert.strictEqual(findAll('tbody tr').length, principalsCount);
assert.dom(commonSelectors.TABLE_ROW).exists({ count: principalsCount });
// Remove a principal to populate association view
await click('tbody tr td:last-child .hds-dropdown-toggle-icon');
await click('tbody tr .hds-dropdown-list-item button');
assert.strictEqual(findAll('tbody tr').length, principalsCount - 1);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(ADD_PRINCIPALS_SELECTOR);
await click(commonSelectors.TABLE_FIRST_ROW_ACTION_DROPDOWN);
await click(commonSelectors.TABLE_FIRST_ROW_ACTION_DROPDOWN_ITEM_BTN);
assert
.dom(commonSelectors.TABLE_ROW)
.exists({ count: principalsCount - 1 });
await click(selectors.MANAGE_DROPDOWN_ROLES);
await click(selectors.MANAGE_DROPDOWN_ADD_PRINCIPALS);
assert.strictEqual(currentURL(), urls.addPrincipals);
await click('tbody label');
await click('form [type="button"]');
await click(commonSelectors.TABLE_ROW_CHECKBOX);
await click(commonSelectors.CANCEL_BTN);
await visit(urls.rolePrincipals);
assert.strictEqual(findAll('tbody tr').length, principalsCount - 1);
assert
.dom(commonSelectors.TABLE_ROW)
.exists({ count: principalsCount - 1 });
});
test('shows error message on principal add', async function (assert) {
@@ -162,8 +190,12 @@ module('Acceptance | roles | principals', function (hooks) {
});
instances.role.update({ userIds: [], groupIds: [], managedGroupIds: [] });
await visit(urls.addPrincipals);
await click('tbody label');
await click('form [type="submit"]');
assert.ok(find(commonSelectors.ALERT_TOAST_BODY));
await click(commonSelectors.TABLE_ROW_CHECKBOX);
await click(commonSelectors.SAVE_BTN);
assert
.dom(commonSelectors.ALERT_TOAST_BODY)
.hasText('The request was invalid.');
});
});
@@ -10,22 +10,13 @@ import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { GRANT_SCOPE_THIS } from 'api/models/role';
import * as selectors from './selectors';
import * as commonSelectors from 'admin/tests/helpers/selectors';
module('Acceptance | roles | project-scope', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const GRANT_SCOPE_ROW_SELECTOR = (id) =>
`tbody [data-test-grant-scope-row="${id}"]`;
const TABLE_ROW_SELECTOR = 'tbody tr';
const MANAGE_DROPDOWN_SELECTOR = '[data-test-manage-roles-dropdown] button';
const MANAGE_SCOPES_SELECTOR = '[data-test-manage-dropdown-scopes]';
const SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]';
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 PAGINATION_SELECTOR = '.hds-pagination';
const instances = {
scopes: {
global: null,
@@ -64,42 +55,42 @@ module('Acceptance | roles | project-scope', function (hooks) {
test('visiting role scopes', async function (assert) {
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await click(commonSelectors.HREF(urls.roleScopes));
await a11yAudit();
assert.strictEqual(currentURL(), urls.roleScopes);
assert.dom(GRANT_SCOPE_ROW_SELECTOR(GRANT_SCOPE_THIS)).exists();
assert.dom(selectors.GRANT_SCOPE_ROW(GRANT_SCOPE_THIS)).isVisible();
assert
.dom(TABLE_ROW_SELECTOR)
.dom(commonSelectors.TABLE_ROW)
.exists({ count: instances.role.grant_scope_ids.length });
});
test('search and pagination is not visible for project role scopes', async function (assert) {
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await click(commonSelectors.HREF(urls.roleScopes));
assert.strictEqual(currentURL(), urls.roleScopes);
assert.dom(SEARCH_INPUT_SELECTOR).doesNotExist();
assert.dom(PAGINATION_SELECTOR).doesNotExist();
assert.dom(commonSelectors.SEARCH_INPUT).doesNotExist();
assert.dom(commonSelectors.PAGINATION).doesNotExist();
});
test('user cannot manage scopes for project role scopes', async function (assert) {
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(commonSelectors.HREF(urls.roleScopes));
await click(selectors.MANAGE_DROPDOWN_ROLES);
assert.dom(MANAGE_SCOPES_SELECTOR).doesNotExist();
assert.dom(selectors.MANAGE_DROPDOWN_ROLES_SCOPES).doesNotExist();
});
test('user sees no scopes message without action when role has no grant scopes', async function (assert) {
instances.role.update({ grant_scope_ids: [] });
await visit(urls.role);
await click(`[href="${urls.roleScopes}"]`);
await click(commonSelectors.HREF(urls.roleScopes));
assert.dom(NO_SCOPES_MSG_SELECTOR).includesText('No scopes added');
assert.dom(NO_SCOPES_MSG_LINK_SELECTOR).doesNotExist();
assert.dom(selectors.NO_SCOPES_MSG).includesText('No scopes added');
assert.dom(selectors.NO_SCOPES_MSG_LINK).doesNotExist();
});
});
@@ -12,6 +12,8 @@ export const MANAGE_DROPDOWN_ROLES_SCOPES =
'[data-test-manage-dropdown-scopes]';
export const MANAGE_DROPDOWN_ROLES_REMOVE =
'[data-test-manage-roles-dropdown] div:last-child button';
export const MANAGE_DROPDOWN_ADD_PRINCIPALS =
'[data-test-manage-role-principals]';
export const ROLE_BADGE = (id) =>
`tbody [data-test-role-row="${id}"] td:nth-child(2) .hds-badge__text`;