From 98d19ef5912cdf0c4143218e866f03844010922f Mon Sep 17 00:00:00 2001 From: Cameron Perera Date: Fri, 18 Oct 2024 09:56:31 -0500 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20new=20selectors=20?= =?UTF-8?q?for=20accounts=20acceptance=20tests=20(#2525)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-14036 --- .../accounts/change-password-test.js | 59 +++++++++++++------ .../tests/acceptance/accounts/selectors.js | 13 ++++ ui/admin/tests/helpers/selectors.js | 2 + 3 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 ui/admin/tests/acceptance/accounts/selectors.js diff --git a/ui/admin/tests/acceptance/accounts/change-password-test.js b/ui/admin/tests/acceptance/accounts/change-password-test.js index e3226fe0c..034636019 100644 --- a/ui/admin/tests/acceptance/accounts/change-password-test.js +++ b/ui/admin/tests/acceptance/accounts/change-password-test.js @@ -4,7 +4,7 @@ */ import { module, test } from 'qunit'; -import { visit, currentURL, click, find, fillIn } from '@ember/test-helpers'; +import { visit, currentURL, click, fillIn } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import { setupIndexedDb } from 'api/test-support/helpers/indexed-db'; @@ -16,6 +16,8 @@ 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 | change password', function (hooks) { setupApplicationTest(hooks); @@ -58,7 +60,7 @@ module('Acceptance | accounts | change password', function (hooks) { test('visiting account change password', async function (assert) { await visit(urls.orgScope); - await click(`[href="${urls.changePassword}"]`); + await click(commonSelectors.HREF(urls.changePassword)); await a11yAudit(); assert.strictEqual(currentURL(), urls.changePassword); @@ -67,11 +69,10 @@ module('Acceptance | accounts | change password', function (hooks) { test('visiting account change password from header', async function (assert) { await visit(urls.orgScope); // Open header utilities dropdown - await click('.rose-header-utilities .rose-dropdown summary'); + await click(selectors.APP_HEADER_DROPDOWN); // Find first element in dropdown - should be change password link - await click( - '.rose-header-utilities .rose-dropdown .rose-dropdown-content a', - ); + await click(commonSelectors.HREF(urls.changePassword)); + assert.strictEqual(currentURL(), urls.changePassword); }); @@ -102,17 +103,33 @@ module('Acceptance | accounts | change password', function (hooks) { }, ); await visit(urls.changePassword); - await fillIn('[name="currentPassword"]', 'current password'); - await fillIn('[name="newPassword"]', 'new password'); - await click('form [type="submit"]:not(:disabled)'); + + await fillIn( + selectors.FIELD_CURRENT_PASSWORD, + selectors.FIELD_CURRENT_PASSWORD_VALUE, + ); + await fillIn( + selectors.FIELD_NEW_PASSWORD, + selectors.FIELD_NEW_PASSWORD_VALUE, + ); + await click(commonSelectors.SAVE_BTN); + await a11yAudit(); }); test('can cancel password change', async function (assert) { await visit(urls.changePassword); - await fillIn('[name="currentPassword"]', 'current password'); - await fillIn('[name="newPassword"]', 'new password'); - await click('.hds-button--color-secondary'); + + await fillIn( + selectors.FIELD_CURRENT_PASSWORD, + selectors.FIELD_CURRENT_PASSWORD_VALUE, + ); + await fillIn( + selectors.FIELD_NEW_PASSWORD, + selectors.FIELD_NEW_PASSWORD_VALUE, + ); + await click(commonSelectors.CANCEL_BTN); + assert.notEqual(currentURL(), urls.changePassword); }); @@ -130,18 +147,26 @@ module('Acceptance | accounts | change password', function (hooks) { }); await visit(urls.orgScope); - await click(`[href="${urls.changePassword}"]`); - await fillIn('[name="currentPassword"]', 'current password'); - await fillIn('[name="newPassword"]', 'new password'); - await click('form [type="submit"]'); + await click(commonSelectors.HREF(urls.changePassword)); + await fillIn( + selectors.FIELD_CURRENT_PASSWORD, + selectors.FIELD_CURRENT_PASSWORD_VALUE, + ); + await fillIn( + selectors.FIELD_NEW_PASSWORD, + selectors.FIELD_NEW_PASSWORD_VALUE, + ); + await click(commonSelectors.SAVE_BTN); await a11yAudit(); - assert.ok(find('[role="alert"]')); + assert.dom(commonSelectors.ALERT_TOAST).isVisible(); }); test('cannot change password when not authenticated', async function (assert) { invalidateSession(); + await visit(urls.changePassword); + assert.notEqual(currentURL(), urls.changePassword); }); }); diff --git a/ui/admin/tests/acceptance/accounts/selectors.js b/ui/admin/tests/acceptance/accounts/selectors.js new file mode 100644 index 000000000..29bc39a43 --- /dev/null +++ b/ui/admin/tests/acceptance/accounts/selectors.js @@ -0,0 +1,13 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + +export const APP_HEADER_DROPDOWN = + '.rose-header-utilities details:first-child summary'; + +export const FIELD_CURRENT_PASSWORD = '[name=currentPassword]'; +export const FIELD_CURRENT_PASSWORD_VALUE = 'current password'; + +export const FIELD_NEW_PASSWORD = '[name=newPassword]'; +export const FIELD_NEW_PASSWORD_VALUE = 'new password'; diff --git a/ui/admin/tests/helpers/selectors.js b/ui/admin/tests/helpers/selectors.js index 449ea6795..24b6a065a 100644 --- a/ui/admin/tests/helpers/selectors.js +++ b/ui/admin/tests/helpers/selectors.js @@ -21,3 +21,5 @@ export const PAGE_MESSAGE_LINK = '.rose-message-body .hds-link-standalone'; export const HREF = (url) => `[href="${url}"]`; export const SIDEBAR_NAV_LINK = (url) => `[title="General"] a[href="${url}"]`; + +export const ALERT_TOAST = '[role="alert"]';