From abf7866292e8440942b45b5ef5eb7037f59b4c7d Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 20 Jun 2025 10:32:28 -0700 Subject: [PATCH] Refactor scopes test selectors (#2888) --- .../app/components/scope-picker/index.hbs | 1 + .../acceptance/auth-methods/create-test.js | 4 +- .../acceptance/auth-methods/selectors.js | 1 - .../acceptance/auth-methods/update-test.js | 2 +- ui/admin/tests/acceptance/scopes-test.js | 51 +++++++++---------- ui/admin/tests/helpers/selectors.js | 5 ++ 6 files changed, 34 insertions(+), 30 deletions(-) diff --git a/ui/admin/app/components/scope-picker/index.hbs b/ui/admin/app/components/scope-picker/index.hbs index a3a504808..1d42c5bee 100644 --- a/ui/admin/app/components/scope-picker/index.hbs +++ b/ui/admin/app/components/scope-picker/index.hbs @@ -8,6 +8,7 @@ @matchToggleWidth={{true}} {{! HDS provided class to automatically fade in/out }} class='hds-side-nav-hide-when-minimized scope-picker' + data-test-side-nav-scope-dropdown as |D| > {{#let this.currentScope as |scope|}} diff --git a/ui/admin/tests/acceptance/auth-methods/create-test.js b/ui/admin/tests/acceptance/auth-methods/create-test.js index 9cb4466d5..af44bd330 100644 --- a/ui/admin/tests/acceptance/auth-methods/create-test.js +++ b/ui/admin/tests/acceptance/auth-methods/create-test.js @@ -544,7 +544,9 @@ module('Acceptance | auth-methods | create', function (hooks) { assert .dom(commonSelectors.ALERT_TOAST_BODY) .hasText('The request was invalid.'); - assert.dom(selectors.FIELD_ERROR).hasText('At least one URL is required.'); + assert + .dom(commonSelectors.FIELD_ERROR) + .hasText('At least one URL is required.'); }); test('users cannot directly navigate to new auth method route without proper authorization', async function (assert) { diff --git a/ui/admin/tests/acceptance/auth-methods/selectors.js b/ui/admin/tests/acceptance/auth-methods/selectors.js index abafef2ec..362ca5a40 100644 --- a/ui/admin/tests/acceptance/auth-methods/selectors.js +++ b/ui/admin/tests/acceptance/auth-methods/selectors.js @@ -94,7 +94,6 @@ export const FIELD_GROUP_FILTER = '[name=group_filter]'; export const FIELD_GROUP_FILTER_VALUE = 'Group filter value'; export const FIELD_ENABLE_GROUPS = '[name=enable_groups]'; export const FIELD_USE_TOKEN_GROUPS = '[name=use_token_groups]'; -export const FIELD_ERROR = '.hds-form-error__message'; // Selects any error message on the DOM. export const MANAGE_DROPDOWN = '[data-test-manage-auth-method] button'; export const MANAGE_DROPDOWN_MAKE_PRIMARY = diff --git a/ui/admin/tests/acceptance/auth-methods/update-test.js b/ui/admin/tests/acceptance/auth-methods/update-test.js index dda2abea6..ff8744f9d 100644 --- a/ui/admin/tests/acceptance/auth-methods/update-test.js +++ b/ui/admin/tests/acceptance/auth-methods/update-test.js @@ -483,6 +483,6 @@ module('Acceptance | auth-methods | update', function (hooks) { await a11yAudit(); assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText(errorMessage); - assert.dom(selectors.FIELD_ERROR).hasText(errorDescription); + assert.dom(commonSelectors.FIELD_ERROR).hasText(errorDescription); }); }); diff --git a/ui/admin/tests/acceptance/scopes-test.js b/ui/admin/tests/acceptance/scopes-test.js index 6592f0f8f..43e556c23 100644 --- a/ui/admin/tests/acceptance/scopes-test.js +++ b/ui/admin/tests/acceptance/scopes-test.js @@ -18,12 +18,6 @@ module('Acceptance | scopes', function (hooks) { setupMirage(hooks); setupIndexedDb(hooks); - const SCOPES_DROPDOWN_BTN = '.scope-picker button'; - const SCOPES_DROPDOWN_SELECTOR = (url) => `.scope-picker [href="${url}"]`; - const SAVE_BUTTON_SELECTOR = '[type="submit"]'; - const CANCEL_BUTTON_SELECTOR = '.rose-form-actions [type="button"]'; - const NAME_FIELD_SELECTOR = '[name="name"]'; - let getScopeCount; const instances = { @@ -92,6 +86,7 @@ module('Acceptance | scopes', function (hooks) { test('visiting global scope', async function (assert) { await visit(urls.globalScope); await a11yAudit(); + assert.strictEqual(currentURL(), urls.globalScope); }); @@ -106,6 +101,7 @@ module('Acceptance | scopes', function (hooks) { return response; }); await visit(urls.globalScope); + assert.strictEqual(currentURL(), urls.globalScope); }); @@ -122,12 +118,13 @@ module('Acceptance | scopes', function (hooks) { assert.strictEqual(currentURL(), urls.globalScope); - await click(SCOPES_DROPDOWN_BTN); - await click(SCOPES_DROPDOWN_SELECTOR(urls.orgScope)); + await click(commonSelectors.SIDEBAR_SCOPE_DROPDOWN); + await click(commonSelectors.SIDEBAR_SCOPE_LINK(urls.orgScope)); assert.strictEqual(currentURL(), urls.orgScopes); - await click(SCOPES_DROPDOWN_BTN); - await click(SCOPES_DROPDOWN_SELECTOR(urls.org2Scope)); + await click(commonSelectors.SIDEBAR_SCOPE_DROPDOWN); + await click(commonSelectors.SIDEBAR_SCOPE_LINK(urls.org2Scope)); + assert.strictEqual(currentURL(), urls.org2Scopes); }); @@ -137,8 +134,8 @@ module('Acceptance | scopes', function (hooks) { assert.strictEqual(currentURL(), urls.projectTargets); - await click(SCOPES_DROPDOWN_BTN); - await click(SCOPES_DROPDOWN_SELECTOR(urls.project2Scope)); + await click(commonSelectors.SIDEBAR_SCOPE_DROPDOWN); + await click(commonSelectors.SIDEBAR_SCOPE_LINK(urls.project2Scope)); assert.strictEqual(currentURL(), urls.project2Targets); }); @@ -147,9 +144,9 @@ module('Acceptance | scopes', function (hooks) { const orgScopeCount = getScopeCount('org'); await visit(urls.globalScope); - await click(`[href="${urls.newOrgScope}"]`); - await fillIn(NAME_FIELD_SELECTOR, 'random string'); - await click(SAVE_BUTTON_SELECTOR); + await click(commonSelectors.HREF(urls.newOrgScope)); + await fillIn(commonSelectors.FIELD_NAME, 'random string'); + await click(commonSelectors.SAVE_BTN); assert.strictEqual(getScopeCount('org'), orgScopeCount + 1); }); @@ -158,9 +155,9 @@ module('Acceptance | scopes', function (hooks) { const orgScopeCount = getScopeCount('project'); await visit(urls.orgScopes); - await click(`[href="${urls.newProjectScope}"]`); - await fillIn(NAME_FIELD_SELECTOR, 'random string'); - await click(SAVE_BUTTON_SELECTOR); + await click(commonSelectors.HREF(urls.newProjectScope)); + await fillIn(commonSelectors.FIELD_NAME, 'random string'); + await click(commonSelectors.SAVE_BTN); assert.strictEqual(getScopeCount('project'), orgScopeCount + 1); }); @@ -169,9 +166,9 @@ module('Acceptance | scopes', function (hooks) { const orgScopeCount = getScopeCount('org'); await visit(urls.globalScope); - await click(`[href="${urls.newOrgScope}"]`); - await fillIn(NAME_FIELD_SELECTOR, 'random string'); - await click(CANCEL_BUTTON_SELECTOR); + await click(commonSelectors.HREF(urls.newOrgScope)); + await fillIn(commonSelectors.FIELD_NAME, 'random string'); + await click(commonSelectors.CANCEL_BTN); assert.strictEqual(currentURL(), urls.globalScope); assert.strictEqual(getScopeCount('org'), orgScopeCount); @@ -181,9 +178,9 @@ module('Acceptance | scopes', function (hooks) { const projectScopeCount = getScopeCount('project'); await visit(urls.orgScopes); - await click(`[href="${urls.newProjectScope}"]`); - await fillIn(NAME_FIELD_SELECTOR, 'random string'); - await click(CANCEL_BUTTON_SELECTOR); + await click(commonSelectors.HREF(urls.newProjectScope)); + await fillIn(commonSelectors.FIELD_NAME, 'random string'); + await click(commonSelectors.CANCEL_BTN); assert.strictEqual(currentURL(), urls.orgScopes); assert.strictEqual(getScopeCount('project'), projectScopeCount); @@ -211,12 +208,12 @@ module('Acceptance | scopes', function (hooks) { }); await visit(urls.globalScope); - await click(`[href="${urls.newOrgScope}"]`); - await click(SAVE_BUTTON_SELECTOR); + await click(commonSelectors.HREF(urls.newOrgScope)); + await click(commonSelectors.SAVE_BTN); assert .dom(commonSelectors.ALERT_TOAST_BODY) .hasText('The request was invalid.'); - assert.dom('.hds-form-error__message').hasText('Name is required.'); + assert.dom(commonSelectors.FIELD_ERROR).hasText('Name is required.'); }); }); diff --git a/ui/admin/tests/helpers/selectors.js b/ui/admin/tests/helpers/selectors.js index 182068af3..e77aa09e3 100644 --- a/ui/admin/tests/helpers/selectors.js +++ b/ui/admin/tests/helpers/selectors.js @@ -18,6 +18,7 @@ export const FIELD_DESCRIPTION_VALUE = 'description'; export const FIELD_PASSWORD = '[name=password]'; export const FIELD_PASSWORD_VALUE = 'password'; +export const FIELD_ERROR = '.hds-form-error__message'; // Selects any error message on the DOM. export const FIELD_IDENTIFICATION = '[name=identification]'; export const TABLE_RESOURCE_LINK = (url) => `tbody [href="${url}"]`; @@ -47,6 +48,10 @@ export const SIDEBAR_NAV_LINK = (url) => export const SIDEBAR_NAV_CONTENT = '.hds-side-nav__content'; export const SIDEBAR_USER_DROPDOWN = '[data-test-side-nav-user-dropdown] button'; +export const SIDEBAR_SCOPE_DROPDOWN = + '[data-test-side-nav-scope-dropdown] button'; +export const SIDEBAR_SCOPE_LINK = (url) => + `[data-test-side-nav-scope-dropdown] a[href="${url}"]`; export const TOGGLE_THEME_DEFAULT = '[data-test-side-nav-user-dropdown] [value=system-default-theme]'; export const TOGGLE_THEME_LIGHT =