From 7f7f0f1859629c8a7cd1258566d134783e5a0fc8 Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Wed, 23 Oct 2024 11:33:55 -0500 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20update=20test=20selector?= =?UTF-8?q?s=20for=20accounts=20delete=20(#2532)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-14038 --- .../tests/acceptance/accounts/create-test.js | 6 +-- .../tests/acceptance/accounts/delete-test.js | 40 ++++++++++--------- .../tests/acceptance/accounts/selectors.js | 8 ++-- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/ui/admin/tests/acceptance/accounts/create-test.js b/ui/admin/tests/acceptance/accounts/create-test.js index 6f1a4ec51..b1d748185 100644 --- a/ui/admin/tests/acceptance/accounts/create-test.js +++ b/ui/admin/tests/acceptance/accounts/create-test.js @@ -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( diff --git a/ui/admin/tests/acceptance/accounts/delete-test.js b/ui/admin/tests/acceptance/accounts/delete-test.js index 2fb55237e..68fa74aaf 100644 --- a/ui/admin/tests/acceptance/accounts/delete-test.js +++ b/ui/admin/tests/acceptance/accounts/delete-test.js @@ -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.'); }); }); diff --git a/ui/admin/tests/acceptance/accounts/selectors.js b/ui/admin/tests/acceptance/accounts/selectors.js index b98b4b4c3..952933231 100644 --- a/ui/admin/tests/acceptance/accounts/selectors.js +++ b/ui/admin/tests/acceptance/accounts/selectors.js @@ -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';