From c38ba294cc66fada0aae3ff6fe58d4da475652b1 Mon Sep 17 00:00:00 2001 From: Wadi <58947248+CaptFalc@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:30:57 -0400 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20Update=20Manage=20Dr?= =?UTF-8?q?opdown=20in=20auth-methods=20(#2460)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 Update Manage Dropdown in auth-methods ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-14704 * refactor: 💡 Refactored tests ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-14704 --------- Co-authored-by: Cameron Perera --- .../auth-method/actions/index.hbs | 53 +++++++------------ .../tests/acceptance/accounts/create-test.js | 3 ++ .../tests/acceptance/accounts/list-test.js | 8 ++- .../acceptance/auth-methods/create-test.js | 12 ++++- .../acceptance/auth-methods/delete-test.js | 37 ++++++++----- .../acceptance/managed-groups/create-test.js | 10 +++- .../acceptance/managed-groups/list-test.js | 5 +- 7 files changed, 78 insertions(+), 50 deletions(-) diff --git a/ui/admin/app/components/auth-methods/auth-method/actions/index.hbs b/ui/admin/app/components/auth-methods/auth-method/actions/index.hbs index ea91c11c7..51296ff10 100644 --- a/ui/admin/app/components/auth-methods/auth-method/actions/index.hbs +++ b/ui/admin/app/components/auth-methods/auth-method/actions/index.hbs @@ -40,55 +40,42 @@ {{/if}} - + + {{#if @model.isPrimary}} - - {{t 'resources.auth-method.actions.remove-as-primary'}} - + /> {{else}} - - {{t 'resources.auth-method.actions.make-primary'}} - + /> {{/if}} {{#if (can 'create model' @model collection='accounts')}} - - - {{t 'resources.account.actions.create'}} - + /> {{/if}} - {{#if (can 'create model' @model collection='managed-groups')}} {{#if (or @model.isOIDC @model.isLDAP)}} - - {{t 'resources.managed-group.actions.create'}} - + /> {{/if}} {{/if}} {{#if (can 'delete auth-method' @model)}} - - + - {{t 'resources.auth-method.actions.delete'}} - + /> {{/if}} - \ No newline at end of file + \ No newline at end of file diff --git a/ui/admin/tests/acceptance/accounts/create-test.js b/ui/admin/tests/acceptance/accounts/create-test.js index 898fc1f1c..c9f7a97e2 100644 --- a/ui/admin/tests/acceptance/accounts/create-test.js +++ b/ui/admin/tests/acceptance/accounts/create-test.js @@ -20,6 +20,8 @@ module('Acceptance | accounts | create', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); + const MANAGE_DROPDOWN_SELECTOR = + '[data-test-manage-auth-methods-dropdown] div:first-child button'; const instances = { scopes: { global: null, @@ -116,6 +118,7 @@ module('Acceptance | accounts | create', function (hooks) { 'create', ), ); + await click(MANAGE_DROPDOWN_SELECTOR); assert.ok(find(`[href="${urls.newAccount}"]`)); }); diff --git a/ui/admin/tests/acceptance/accounts/list-test.js b/ui/admin/tests/acceptance/accounts/list-test.js index 9d981697d..5463be25e 100644 --- a/ui/admin/tests/acceptance/accounts/list-test.js +++ b/ui/admin/tests/acceptance/accounts/list-test.js @@ -18,6 +18,11 @@ module('Acceptance | accounts | list', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); + const MANAGE_DROPDOWN_SELECTOR = + '[data-test-manage-auth-methods-dropdown] div:first-child button'; + const CREATE_ACCOUNT_SELECTOR = + '[data-test-manage-auth-methods-dropdown] ul li:nth-child(2) a'; + const instances = { scopes: { global: null, @@ -89,6 +94,7 @@ module('Acceptance | accounts | list', function (hooks) { instances.authMethod.authorized_collection_actions.accounts = ['create']; await visit(urls.authMethod); assert.ok(find(`[href="${urls.accounts}"]`)); - assert.ok(find(`.rose-layout-page-actions [href="${urls.newAccount}"]`)); + await click(MANAGE_DROPDOWN_SELECTOR); + assert.dom(CREATE_ACCOUNT_SELECTOR).hasAttribute('href', urls.newAccount); }); }); diff --git a/ui/admin/tests/acceptance/auth-methods/create-test.js b/ui/admin/tests/acceptance/auth-methods/create-test.js index 9a4ed2cc1..23a3faf45 100644 --- a/ui/admin/tests/acceptance/auth-methods/create-test.js +++ b/ui/admin/tests/acceptance/auth-methods/create-test.js @@ -32,8 +32,6 @@ module('Acceptance | auth-methods | create', function (hooks) { const NAME_INPUT_SELECTOR = '[name="name"]'; const URLS_INPUT_SELECTOR = '[name="urls"]'; const DESC_INPUT_SELECTOR = '[name="description"]'; - const MAKE_PRIMARY_SELECTOR = - '.rose-layout-page-actions .rose-dropdown-content [type="button"]:first-child'; const ERROR_MSG_SELECTOR = '.rose-notification-body'; const FIELD_ERROR_TEXT_SELECTOR = '.hds-form-error__message'; @@ -48,6 +46,12 @@ module('Acceptance | auth-methods | create', function (hooks) { const CLAIMS_SCOPES_BTN_SELECTOR = '[name="claims_scopes"] button'; const CLAIMS_SCOPES_INPUT_SELECTOR = '[name="claims_scopes"] input'; const TOGGLE_SELECTOR = '[name="prompts"]'; + + const MANAGE_DROPDOWN_SELECTOR = + '[data-test-manage-auth-methods-dropdown] div:first-child button'; + const MAKE_PRIMARY_SELECTOR = + '[data-test-manage-auth-methods-dropdown] ul li:first-child button'; + let getAuthMethodsCount; let featuresService; @@ -333,6 +337,7 @@ module('Acceptance | auth-methods | create', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.authMethod}"]`); + await click(MANAGE_DROPDOWN_SELECTOR); await click(MAKE_PRIMARY_SELECTOR); const scope = this.server.schema.scopes.find(instances.orgScope.id); @@ -360,6 +365,7 @@ module('Acceptance | auth-methods | create', function (hooks) { 'Primary auth method is not yet set.', ); await visit(urls.authMethod); + await click(MANAGE_DROPDOWN_SELECTOR); await click(MAKE_PRIMARY_SELECTOR); assert.dom(ERROR_MSG_SELECTOR).exists(); }); @@ -375,6 +381,7 @@ module('Acceptance | auth-methods | create', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.authMethod}"]`); + await click(MANAGE_DROPDOWN_SELECTOR); await click(MAKE_PRIMARY_SELECTOR); const scope = this.server.schema.scopes.find(instances.orgScope.id); assert.notOk(scope.primaryAuthMethodId, 'Primary auth method is unset.'); @@ -403,6 +410,7 @@ module('Acceptance | auth-methods | create', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.authMethod}"]`); + await click(MANAGE_DROPDOWN_SELECTOR); await click(MAKE_PRIMARY_SELECTOR); assert.dom(ERROR_MSG_SELECTOR).hasText('Sorry!'); diff --git a/ui/admin/tests/acceptance/auth-methods/delete-test.js b/ui/admin/tests/acceptance/auth-methods/delete-test.js index 0f75821c7..ae8d019ec 100644 --- a/ui/admin/tests/acceptance/auth-methods/delete-test.js +++ b/ui/admin/tests/acceptance/auth-methods/delete-test.js @@ -26,12 +26,15 @@ module('Acceptance | auth-methods | delete', function (hooks) { let featuresService; let getAuthMethodCount; - const DELETE_DROPDOWN_SELECTOR = - '.rose-layout-page-actions .rose-dropdown-button-danger'; const DIALOG_DELETE_BTN_SELECTOR = '.rose-dialog .rose-button-primary'; const DIALOG_CANCEL_BTN_SELECTOR = '.rose-dialog .rose-button-secondary'; const ERROR_MSG_SELECTOR = '.rose-notification-body'; + const MANAGE_DROPDOWN_SELECTOR = + '[data-test-manage-auth-methods-dropdown] div:first-child button'; + const DELETE_ACTION_SELECTOR = + '[data-test-manage-auth-methods-dropdown] ul li:last-child button'; + const instances = { scopes: { global: null, @@ -78,7 +81,8 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.authMethod}"]`); - await click(DELETE_DROPDOWN_SELECTOR); + await click(MANAGE_DROPDOWN_SELECTOR); + await click(DELETE_ACTION_SELECTOR); assert.strictEqual(getAuthMethodCount(), authMethodsCount - 1); }); @@ -89,7 +93,8 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.ldapAuthMethod}"]`); - await click(DELETE_DROPDOWN_SELECTOR); + await click(MANAGE_DROPDOWN_SELECTOR); + await click(DELETE_ACTION_SELECTOR); assert.strictEqual(getAuthMethodCount(), authMethodsCount - 1); }); @@ -109,7 +114,8 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.authMethod}"]`); - await click(DELETE_DROPDOWN_SELECTOR); + await click(MANAGE_DROPDOWN_SELECTOR); + await click(DELETE_ACTION_SELECTOR); await a11yAudit(); assert.dom(ERROR_MSG_SELECTOR).hasText('Oops.'); @@ -131,7 +137,8 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.ldapAuthMethod}"]`); - await click(DELETE_DROPDOWN_SELECTOR); + await click(MANAGE_DROPDOWN_SELECTOR); + await click(DELETE_ACTION_SELECTOR); await a11yAudit(); assert.dom(ERROR_MSG_SELECTOR).hasText('Oops.'); @@ -145,8 +152,9 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.authMethod}"]`); + await click(MANAGE_DROPDOWN_SELECTOR); - assert.dom(DELETE_DROPDOWN_SELECTOR).doesNotExist(); + assert.dom(DELETE_ACTION_SELECTOR).doesNotExist(); }); test('cannot delete an ldap auth method without proper authorization', async function (assert) { @@ -158,8 +166,9 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.ldapAuthMethod}"]`); + await click(MANAGE_DROPDOWN_SELECTOR); - assert.dom(DELETE_DROPDOWN_SELECTOR).doesNotExist(); + assert.dom(DELETE_ACTION_SELECTOR).doesNotExist(); }); test('user can accept delete auth method via dialog', async function (assert) { @@ -169,7 +178,8 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.authMethod}"]`); - await click(DELETE_DROPDOWN_SELECTOR); + await click(MANAGE_DROPDOWN_SELECTOR); + await click(DELETE_ACTION_SELECTOR); await click(DIALOG_DELETE_BTN_SELECTOR); assert.strictEqual(currentURL(), urls.authMethods); @@ -184,7 +194,8 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.ldapAuthMethod}"]`); - await click(DELETE_DROPDOWN_SELECTOR); + await click(MANAGE_DROPDOWN_SELECTOR); + await click(DELETE_ACTION_SELECTOR); await click(DIALOG_DELETE_BTN_SELECTOR); assert.strictEqual(currentURL(), urls.authMethods); @@ -198,7 +209,8 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.authMethod}"]`); - await click(DELETE_DROPDOWN_SELECTOR); + await click(MANAGE_DROPDOWN_SELECTOR); + await click(DELETE_ACTION_SELECTOR); await click(DIALOG_CANCEL_BTN_SELECTOR); assert.strictEqual(currentURL(), urls.authMethod); @@ -213,7 +225,8 @@ module('Acceptance | auth-methods | delete', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.ldapAuthMethod}"]`); - await click(DELETE_DROPDOWN_SELECTOR); + await click(MANAGE_DROPDOWN_SELECTOR); + await click(DELETE_ACTION_SELECTOR); await click(DIALOG_CANCEL_BTN_SELECTOR); assert.strictEqual(currentURL(), urls.ldapAuthMethod); diff --git a/ui/admin/tests/acceptance/managed-groups/create-test.js b/ui/admin/tests/acceptance/managed-groups/create-test.js index 6c4a55f59..620746549 100644 --- a/ui/admin/tests/acceptance/managed-groups/create-test.js +++ b/ui/admin/tests/acceptance/managed-groups/create-test.js @@ -30,6 +30,8 @@ module('Acceptance | managed-groups | create', function (hooks) { const DESC_INPUT_SELECTOR = '[name="description"]'; const ERROR_MSG_SELECTOR = '.rose-notification-body'; const FIELD_ERROR_TEXT_SELECTOR = '.hds-form-error__message'; + const MANAGE_DROPDOWN_SELECTOR = + '[data-test-manage-auth-methods-dropdown] div button'; const instances = { scopes: { @@ -85,8 +87,9 @@ module('Acceptance | managed-groups | create', function (hooks) { const managedGroupsCount = getManagedGroupCount(); const name = 'Managed group name'; await visit(urls.authMethod); - + await click(MANAGE_DROPDOWN_SELECTOR); await click(`[href="${urls.newManagedGroup}"]`); + await fillIn(NAME_INPUT_SELECTOR, name); await fillIn(DESC_INPUT_SELECTOR, 'description'); await click(SAVE_BTN_SELECTOR); @@ -101,6 +104,7 @@ module('Acceptance | managed-groups | create', function (hooks) { const managedGroupsCount = getManagedGroupCount(); const name = 'Managed group name'; await visit(urls.ldapAuthMethod); + await click(MANAGE_DROPDOWN_SELECTOR); await click(`[href="${urls.newLdapManagedGroup}"]`); await fillIn(NAME_INPUT_SELECTOR, name); @@ -154,6 +158,7 @@ module('Acceptance | managed-groups | create', function (hooks) { test('User can cancel a new managed group creation', async function (assert) { const managedGroupsCount = getManagedGroupCount(); await visit(urls.authMethod); + await click(MANAGE_DROPDOWN_SELECTOR); await click(`[href="${urls.newManagedGroup}"]`); await fillIn(NAME_INPUT_SELECTOR, 'Managed group name'); @@ -166,6 +171,7 @@ module('Acceptance | managed-groups | create', function (hooks) { test('User can cancel a new ldap managed group creation', async function (assert) { const managedGroupsCount = getManagedGroupCount(); await visit(urls.ldapAuthMethod); + await click(MANAGE_DROPDOWN_SELECTOR); await click(`[href="${urls.newLdapManagedGroup}"]`); await fillIn(NAME_INPUT_SELECTOR, 'Managed group name'); @@ -196,6 +202,7 @@ module('Acceptance | managed-groups | create', function (hooks) { ); }); await visit(urls.authMethod); + await click(MANAGE_DROPDOWN_SELECTOR); await click(`[href="${urls.newManagedGroup}"]`); await fillIn(NAME_INPUT_SELECTOR, 'new managed group'); @@ -227,6 +234,7 @@ module('Acceptance | managed-groups | create', function (hooks) { ); }); await visit(urls.ldapAuthMethod); + await click(MANAGE_DROPDOWN_SELECTOR); await click(`[href="${urls.newLdapManagedGroup}"]`); await fillIn(NAME_INPUT_SELECTOR, 'new managed group'); diff --git a/ui/admin/tests/acceptance/managed-groups/list-test.js b/ui/admin/tests/acceptance/managed-groups/list-test.js index f42ef7436..b25356ea6 100644 --- a/ui/admin/tests/acceptance/managed-groups/list-test.js +++ b/ui/admin/tests/acceptance/managed-groups/list-test.js @@ -20,6 +20,8 @@ module('Acceptance | managed-groups | list', function (hooks) { setupIndexedDb(hooks); let featuresService; + const MANAGE_DROPDOWN_SELECTOR = + '[data-test-manage-auth-methods-dropdown] div button'; const instances = { scopes: { @@ -157,6 +159,7 @@ module('Acceptance | managed-groups | list', function (hooks) { await visit(urls.authMethods); await click(`[href="${urls.authMethod}"]`); + await click(MANAGE_DROPDOWN_SELECTOR); assert.dom(`[href="${urls.managedGroups}"]`).exists(); assert.dom(`[href="${urls.newManagedGroup}"]`).exists(); @@ -168,8 +171,8 @@ module('Acceptance | managed-groups | list', function (hooks) { 'create', ]; await visit(urls.authMethods); - await click(`[href="${urls.ldapAuthMethod}"]`); + await click(MANAGE_DROPDOWN_SELECTOR); assert.dom(`[href="${urls.ldapManagedGroups}"]`).exists(); assert.dom(`[href="${urls.newLdapManagedGroup}"]`).exists();