Icu 16406 roles read, update, delete (#2741)

* chore: 🤖 add test selectors to roles read tests

* chore: 🤖 add test selectors to roles update tests

* refactor: 💡 small test clean up

* chore: 🤖 add test selectors to roles delete tests
This commit is contained in:
Cameron Perera authored and GitHub committed 2025-03-21 15:34:17 -05:00
1 parent 777e40fff8
commit ddbd1ca163
7 files changed
+79 -59

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@
{{#if @model.errors.name}}
<F.Error as |E|>
{{#each @model.errors.name as |error|}}
<E.Message>{{error.message}}</E.Message>
<E.Message data-test-error-message-name>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
@@ -3,7 +3,7 @@
SPDX-License-Identifier: BUSL-1.1
}}
<Hds::Dropdown as |dd|>
<Hds::Dropdown data-test-manage-roles-dropdown as |dd|>
<dd.ToggleButton @text={{t 'actions.manage'}} @color='secondary' />
{{#if (can 'addPrincipals role' @model)}}
<dd.Interactive
@@ -56,12 +56,12 @@ module('Acceptance | accounts | update', function (hooks) {
await visit(urls.account);
await click(commonSelectors.EDIT_BTN);
await fillIn(commonSelectors.FIELD_NAME, 'updated name');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await click(commonSelectors.SAVE_BTN);
assert.strictEqual(
this.server.schema.accounts.all().models[0].name,
'updated name',
commonSelectors.FIELD_NAME_VALUE,
);
});
@@ -69,17 +69,20 @@ module('Acceptance | accounts | update', function (hooks) {
await visit(urls.account);
await click(commonSelectors.EDIT_BTN);
await fillIn(commonSelectors.FIELD_NAME, 'updated name');
await fillIn(commonSelectors.FIELD_DESCRIPTION, 'updated desc');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await fillIn(
commonSelectors.FIELD_DESCRIPTION,
commonSelectors.FIELD_DESCRIPTION_VALUE,
);
await click(commonSelectors.SAVE_BTN);
assert.strictEqual(
this.server.schema.accounts.all().models[0].name,
'updated name',
commonSelectors.FIELD_NAME_VALUE,
);
assert.strictEqual(
this.server.schema.accounts.all().models[0].description,
'updated desc',
commonSelectors.FIELD_DESCRIPTION_VALUE,
);
});
@@ -94,17 +97,13 @@ module('Acceptance | accounts | update', function (hooks) {
test('can update an account and cancel changes', async function (assert) {
await visit(urls.account);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'updated name');
await click('form button:not([type="submit"])');
await click(commonSelectors.EDIT_BTN);
await fillIn(commonSelectors.FIELD_NAME, 'updated name');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await click(commonSelectors.CANCEL_BTN);
assert.notEqual(
this.server.schema.accounts.all().models[0].name,
'updated name',
commonSelectors.FIELD_NAME_VALUE,
);
});
@@ -123,7 +122,7 @@ module('Acceptance | accounts | update', function (hooks) {
await visit(urls.account);
await click(commonSelectors.EDIT_BTN);
await fillIn(commonSelectors.FIELD_NAME, 'updated name');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await click(commonSelectors.SAVE_BTN);
await a11yAudit();
@@ -153,7 +152,7 @@ module('Acceptance | accounts | update', function (hooks) {
await visit(urls.account);
await click(commonSelectors.EDIT_BTN);
await fillIn(commonSelectors.FIELD_NAME, 'existing account');
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await click(commonSelectors.SAVE_BTN);
await a11yAudit();
+14 -13
View File
@@ -4,21 +4,18 @@
*/
import { module, test } from 'qunit';
import { visit, click, find } from '@ember/test-helpers';
import { visit, click } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
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 | delete', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const MANAGE_DROPDOWN_SELECTOR = '.hds-dropdown-toggle-button';
const DELETE_DROPDOWN_SELECTOR =
'.hds-dropdown-list-item--color-critical button';
const instances = {
scopes: {
global: null,
@@ -28,7 +25,6 @@ module('Acceptance | roles | delete', function (hooks) {
role: null,
};
const urls = {
orgScope: null,
roles: null,
role: null,
newRole: null,
@@ -63,8 +59,10 @@ module('Acceptance | roles | delete', function (hooks) {
test('can delete a role', async function (assert) {
const rolesCount = this.server.db.roles.length;
await visit(urls.role);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_DROPDOWN_SELECTOR);
await click(selectors.MANAGE_DROPDOWN_ROLES);
await click(selectors.MANAGE_DROPDOWN_ROLES_REMOVE);
assert.strictEqual(this.server.db.roles.length, rolesCount - 1);
});
@@ -72,9 +70,10 @@ module('Acceptance | roles | delete', function (hooks) {
instances.role.authorized_actions =
instances.role.authorized_actions.filter((item) => item !== 'delete');
await visit(urls.role);
assert.notOk(
find('.rose-layout-page-actions .rose-dropdown-button-danger'),
);
await click(selectors.MANAGE_DROPDOWN_ROLES);
assert.dom(selectors.MANAGE_DROPDOWN_ROLES_REMOVE).doesNotExist();
});
test('errors are displayed when delete project fails', async function (assert) {
@@ -90,8 +89,10 @@ module('Acceptance | roles | delete', function (hooks) {
);
});
await visit(urls.role);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_DROPDOWN_SELECTOR);
await click(selectors.MANAGE_DROPDOWN_ROLES);
await click(selectors.MANAGE_DROPDOWN_ROLES_REMOVE);
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Oops.');
});
});
+11 -6
View File
@@ -4,12 +4,13 @@
*/
import { module, test } from 'qunit';
import { visit, currentURL, click, find } from '@ember/test-helpers';
import { visit, currentURL, click } 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 { authenticateSession } from 'ember-simple-auth/test-support';
import * as commonSelectors from 'admin/tests/helpers/selectors';
module('Acceptance | roles | read', function (hooks) {
setupApplicationTest(hooks);
@@ -61,16 +62,17 @@ module('Acceptance | roles | read', function (hooks) {
test('visiting roles', async function (assert) {
await visit(urls.roles);
await a11yAudit();
assert.strictEqual(currentURL(), urls.roles);
});
test('can navigate to a role form', async function (assert) {
await visit(urls.orgScope);
await click(`[href="${urls.roles}"]`);
await click('main tbody .hds-table__tr:nth-child(1) a');
await click(commonSelectors.HREF(urls.roles));
await click(commonSelectors.TABLE_RESOURCE_LINK(urls.role));
await a11yAudit();
assert.strictEqual(currentURL(), urls.role);
});
@@ -78,7 +80,8 @@ module('Acceptance | roles | read', function (hooks) {
instances.role.authorized_actions =
instances.role.authorized_actions.filter((item) => item !== 'read');
await visit(urls.roles);
assert.notOk(find('main tbody .hds-table__tr:nth-child(1) a'));
assert.dom(commonSelectors.TABLE_RESOURCE_LINK(urls.role)).doesNotExist();
});
test('can navigate to a roles and fetches scopes correctly', async function (assert) {
@@ -89,8 +92,10 @@ module('Acceptance | roles | read', function (hooks) {
});
await visit(urls.roles);
await click('main tbody .hds-table__tr:nth-child(1) a');
await click(commonSelectors.TABLE_RESOURCE_LINK(urls.role));
await a11yAudit();
assert.strictEqual(currentURL(), urls.role);
});
@@ -4,3 +4,11 @@
*/
export const NEW_ROLE_BTN = '[data-test-new-role-button]';
export const MANAGE_DROPDOWN_ROLES = '[data-test-manage-roles-dropdown] button';
export const MANAGE_DROPDOWN_ROLES_PRINCIPALS =
'[data-test-manage-dropdown-principals]';
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';
+31 -24
View File
@@ -4,7 +4,7 @@
*/
import { module, test } from 'qunit';
import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers';
import { visit, currentURL, click, fillIn } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { Response } from 'miragejs';
@@ -24,7 +24,6 @@ module('Acceptance | roles | update', function (hooks) {
role: null,
};
const urls = {
orgScope: null,
roles: null,
role: null,
newRole: null,
@@ -58,29 +57,42 @@ module('Acceptance | roles | update', function (hooks) {
test('can save changes to an existing role', async function (assert) {
await visit(urls.role);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Updated admin role');
await click('.rose-form-actions [type="submit"]');
await click(commonSelectors.EDIT_BTN);
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await click(commonSelectors.SAVE_BTN);
assert.strictEqual(currentURL(), urls.role);
assert.strictEqual(this.server.db.roles[0].name, 'Updated admin role');
assert.strictEqual(
this.server.schema.roles.all().models[0].name,
commonSelectors.FIELD_NAME_VALUE,
);
});
test('cannot make changes to an existing role without proper authorization', async function (assert) {
instances.role.authorized_actions =
instances.role.authorized_actions.filter((item) => item !== 'update');
await visit(urls.role);
assert.notOk(find('.rose-layout-page-actions .rose-button-secondary'));
assert.dom(commonSelectors.EDIT_BTN).doesNotExist();
});
test('can cancel changes to an existing role', async function (assert) {
await visit(urls.role);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Updated admin role');
await click('.rose-form-actions [type="button"]');
assert.notEqual(find('[name="name"]').value, 'Updated admin role');
await click(commonSelectors.EDIT_BTN);
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await click(commonSelectors.CANCEL_BTN);
assert.notEqual(
this.server.schema.roles.all().models[0].name,
commonSelectors.FIELD_NAME_VALUE,
);
});
test('saving an existing role with invalid fields displays error messages', async function (assert) {
const errorMessage = 'Error in provided request.';
const errorDescription = 'Must be all lowercase.';
this.server.patch('/roles/:id', () => {
return new Response(
400,
@@ -88,12 +100,12 @@ module('Acceptance | roles | update', function (hooks) {
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
message: errorMessage,
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
description: errorDescription,
},
],
},
@@ -101,16 +113,11 @@ module('Acceptance | roles | update', function (hooks) {
);
});
await visit(urls.role);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert
.dom(commonSelectors.ALERT_TOAST_BODY)
.hasText('The request was invalid.');
assert.strictEqual(
find('.hds-form-error__message').textContent.trim(),
'Name is required.',
'Displays field-level errors.',
);
await click(commonSelectors.EDIT_BTN);
await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE);
await click(commonSelectors.SAVE_BTN);
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText(errorMessage);
assert.dom(commonSelectors.FIELD_NAME_ERROR).hasText(errorDescription);
});
});