test: 💍 update test selectors for accounts delete (#2532)

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-14038
This commit is contained in:
Cameron Perera authored and GitHub committed 2024-10-23 11:33:55 -05:00
1 parent b494a703eb
commit 7f7f0f1859
3 files changed
+29 -25

No files matched your search

@@ -117,7 +117,7 @@ module('Acceptance | accounts | create', function (hooks) {
instances.authMethod.authorized_collection_actions.accounts = [];
await visit(urls.authMethod);
await click(selectors.MANAGE_DROPDOWN);
await click(selectors.MANAGE_DROPDOWN_AUTH_METHOD);
assert.notOk(
instances.authMethod.authorized_collection_actions.accounts.includes(
@@ -130,7 +130,7 @@ module('Acceptance | accounts | create', function (hooks) {
test('Users can navigate to new account route with proper authorization', async function (assert) {
await visit(urls.accounts);
await click(selectors.MANAGE_DROPDOWN);
await click(selectors.MANAGE_DROPDOWN_AUTH_METHOD);
assert.ok(
instances.authMethod.authorized_collection_actions.accounts.includes(
@@ -144,7 +144,7 @@ module('Acceptance | accounts | create', function (hooks) {
instances.authMethod.authorized_collection_actions.accounts = [];
await visit(urls.accounts);
await click(selectors.MANAGE_DROPDOWN);
await click(selectors.MANAGE_DROPDOWN_AUTH_METHOD);
assert.notOk(
instances.authMethod.authorized_collection_actions.accounts.includes(
@@ -15,16 +15,13 @@ import {
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
import * as selectors from './selectors';
import * as commonSelectors from 'admin/tests/helpers/selectors';
module('Acceptance | accounts | delete', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const MANAGE_DROPDOWN_SELECTOR =
'[data-test-manage-account-auth-methods] div:first-child button';
const DELETE_ACTION_SELECTOR =
'[data-test-manage-account-auth-methods] ul li button';
const instances = {
scopes: {
global: null,
@@ -64,25 +61,32 @@ module('Acceptance | accounts | delete', function (hooks) {
});
hooks.afterEach(async function () {
const notification = find('.rose-notification');
const notification = find(commonSelectors.ALERT_TOAST);
if (notification) {
await click('.rose-notification-dismiss');
await click(commonSelectors.ALERT_TOAST_DISMISS);
}
});
test('can delete an account', async function (assert) {
const accountsCount = this.server.db.accounts.length;
const accountsCount = this.server.schema.accounts.all().models.length;
await visit(urls.account);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);
assert.strictEqual(this.server.db.accounts.length, accountsCount - 1);
await click(selectors.MANAGE_DROPDOWN_ACCOUNT);
await click(selectors.MANAGE_DROPDOWN_DELETE_ACCOUNT);
assert.strictEqual(
this.server.schema.accounts.all().models.length,
accountsCount - 1,
);
});
test('cannot delete an account without proper authorization', async function (assert) {
instances.account.authorized_actions =
instances.account.authorized_actions.filter((item) => item !== 'delete');
await visit(urls.account);
assert.dom(MANAGE_DROPDOWN_SELECTOR).doesNotExist();
assert.dom(selectors.MANAGE_DROPDOWN_ACCOUNT).doesNotExist();
});
test('errors are displayed when delete on account fails', async function (assert) {
@@ -98,13 +102,11 @@ module('Acceptance | accounts | delete', function (hooks) {
);
});
await visit(urls.account);
await click(MANAGE_DROPDOWN_SELECTOR);
await click(DELETE_ACTION_SELECTOR);
await click(selectors.MANAGE_DROPDOWN_ACCOUNT);
await click(selectors.MANAGE_DROPDOWN_DELETE_ACCOUNT);
await a11yAudit();
assert.strictEqual(
find('.rose-notification-body').textContent.trim(),
'Oops.',
'Displays primary error message.',
);
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Oops.');
});
});
@@ -6,10 +6,12 @@
export const APP_HEADER_DROPDOWN =
'.rose-header-utilities details:first-child summary';
export const MANAGE_DROPDOWN =
export const MANAGE_DROPDOWN_AUTH_METHOD =
'[data-test-manage-auth-methods-dropdown] button';
export const MANAGE_DROPDOWN_NEW_ACCOUNT = (url) =>
`[data-test-manage-auth-methods-dropdown] a[href="${url}"]`;
export const MANAGE_DROPDOWN_ACCOUNT =
'[data-test-manage-account-auth-methods] button';
export const MANAGE_DROPDOWN_DELETE_ACCOUNT =
'[data-test-manage-account-auth-methods] ul li button';
export const FIELD_CURRENT_PASSWORD = '[name=currentPassword]';
export const FIELD_CURRENT_PASSWORD_VALUE = 'current password';