From d93a0c170c8911a4a55d251680104ddbdbfd367a Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Thu, 10 Jul 2025 16:20:37 -0700 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20refactor=20targets=20man?= =?UTF-8?q?age=20alias=20test=20selectors=20(#2921)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16437 --- .../acceptance/targets/manage-alias-test.js | 56 ++++++++----------- .../tests/acceptance/targets/selectors.js | 3 + 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/ui/admin/tests/acceptance/targets/manage-alias-test.js b/ui/admin/tests/acceptance/targets/manage-alias-test.js index f64b4a56b..a8d3212f1 100644 --- a/ui/admin/tests/acceptance/targets/manage-alias-test.js +++ b/ui/admin/tests/acceptance/targets/manage-alias-test.js @@ -11,18 +11,13 @@ import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { authenticateSession } from 'ember-simple-auth/test-support'; import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target'; import * as commonSelectors from 'admin/tests/helpers/selectors'; +import * as selectors from './selectors'; module('Acceptance | targets | manage-alias', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); + let aliasResourceTwo, aliasResourceOne, getAliasCount; - const ALIASES_SIDEBAR = '.target-sidebar-aliases'; - const ALIASES_SIDEBAR_LIST = '.link-list-item'; - const DROPDOWN_ACTION = '[data-test-manage-target-alias] button'; - const CLEAR_BTN_SELECTOR = '.hds-dropdown-list-item--color-action button'; - const LINK_TO_NEW_ALIAS = '.target-sidebar-aliases .hds-button'; - const DEST_FIELD_SELECTOR = '[name="destination_id"]'; - const ITEM_SELECTOR = '.link-list-item a'; const instances = { scopes: { @@ -34,9 +29,8 @@ module('Acceptance | targets | manage-alias', function (hooks) { tcpTarget: null, alias: null, }; + const urls = { - globalScope: null, - orgScope: null, projectScope: null, targets: null, sshTarget: null, @@ -78,14 +72,11 @@ module('Acceptance | targets | manage-alias', function (hooks) { }); // Generate route URLs for resources - urls.globalScope = `/scopes/global`; - urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; urls.projectScope = `/scopes/${instances.scopes.project.id}`; urls.targets = `${urls.projectScope}/targets`; urls.tcpTarget = `${urls.targets}/${instances.tcpTarget.id}`; urls.sshTarget = `${urls.targets}/${instances.sshTarget.id}`; urls.unknownTarget = `${urls.targets}/foo`; - urls.tcpAlias = `${urls.tcpTarget}/${aliasResourceOne.id}`; getAliasCount = () => this.server.schema.aliases.all().models.length; @@ -95,9 +86,11 @@ module('Acceptance | targets | manage-alias', function (hooks) { test('clicking on manage should take you to manage page', async function (assert) { await visit(urls.tcpTarget); - assert.dom(ALIASES_SIDEBAR).exists(); - assert.dom(ALIASES_SIDEBAR_LIST).exists(); - await click(ITEM_SELECTOR); + + assert.dom(selectors.ALIASES_SIDEBAR).isVisible(); + assert.dom(selectors.ALIASES_SIDEBAR_LIST).isVisible(); + + await click(selectors.LINK_LIST_ITEM); assert.strictEqual(currentURL(), urls.tcpAlias); await a11yAudit(); @@ -108,24 +101,23 @@ module('Acceptance | targets | manage-alias', function (hooks) { destination_id: instances.tcpTarget.id, }); await visit(urls.tcpTarget); - assert.dom(ALIASES_SIDEBAR).exists(); - assert.dom(ALIASES_SIDEBAR_LIST).exists(); - await click(ITEM_SELECTOR); + assert.dom(selectors.ALIASES_SIDEBAR).isVisible(); + assert.dom(selectors.ALIASES_SIDEBAR_LIST).isVisible(); + + await click(selectors.LINK_LIST_ITEM); assert.strictEqual(currentURL(), urls.tcpAlias); - await click(DROPDOWN_ACTION); - await click(CLEAR_BTN_SELECTOR); + await click(selectors.MANAGE_ALIAS_DROPDOWN); + await click(selectors.MANAGE_ALIAS_DROPDOWN_CLEAR); const id = aliasResourceOne.id; const associatedAlias = this.server.schema.aliases.findBy({ id }); assert.strictEqual(associatedAlias.destinationId, null); - assert.strictEqual(currentURL(), urls.tcpTarget); - - assert.dom(ALIASES_SIDEBAR_LIST).doesNotExist(); - assert.dom(LINK_TO_NEW_ALIAS).exists; + assert.dom(selectors.ALIASES_SIDEBAR_LIST).doesNotExist(); + assert.dom(selectors.ALIASES_NEW_LINK).isVisible(); }); test('clicking on `delete alias` from the dropdown should remove the destination ID and alias should disapper from the target sidebar and deleted from aliases list', async function (assert) { @@ -134,23 +126,21 @@ module('Acceptance | targets | manage-alias', function (hooks) { destination_id: instances.tcpTarget.id, }); await visit(urls.tcpTarget); - assert.dom(ALIASES_SIDEBAR).exists(); - assert.dom(ALIASES_SIDEBAR_LIST).exists(); - await click(ITEM_SELECTOR); + assert.dom(selectors.ALIASES_SIDEBAR).isVisible(); + assert.dom(selectors.ALIASES_SIDEBAR_LIST).isVisible(); - assert.dom(DEST_FIELD_SELECTOR).doesNotHaveAttribute('readOnly'); + await click(selectors.LINK_LIST_ITEM); + assert.dom(selectors.FIELD_DESTINATION_ID).doesNotHaveAttribute('readOnly'); assert.strictEqual(currentURL(), urls.tcpAlias); - await click(DROPDOWN_ACTION); + await click(selectors.MANAGE_ALIAS_DROPDOWN); await click(commonSelectors.DELETE_BTN); assert.strictEqual(getAliasCount(), aliasCount - 1); - assert.strictEqual(currentURL(), urls.tcpTarget); - - assert.dom(ALIASES_SIDEBAR_LIST).doesNotExist(); - assert.dom(LINK_TO_NEW_ALIAS).exists; + assert.dom(selectors.ALIASES_SIDEBAR_LIST).doesNotExist(); + assert.dom(selectors.ALIASES_NEW_LINK).isVisible(); }); }); diff --git a/ui/admin/tests/acceptance/targets/selectors.js b/ui/admin/tests/acceptance/targets/selectors.js index b4b0f7804..b95a496fa 100644 --- a/ui/admin/tests/acceptance/targets/selectors.js +++ b/ui/admin/tests/acceptance/targets/selectors.js @@ -35,6 +35,9 @@ export const MANGE_DROPDOWN_ADD_INJECTED_CREDENTIALS = '[data-test-manage-targets-dropdown] [data-test-add-injected-cred-sources-action]'; export const MANAGE_DROPDOWN_ADD_HOST_SOURCES = '[data-test-manage-targets-dropdown] [data-test-add-host-sources-action]'; +export const MANAGE_ALIAS_DROPDOWN = '[data-test-manage-target-alias] button'; +export const MANAGE_ALIAS_DROPDOWN_CLEAR = + '[data-test-manage-target-alias] .hds-dropdown-list-item--color-action button'; export const ALIASES_SIDEBAR = '.target-sidebar-aliases'; export const ALIASES_SIDEBAR_LIST = '.target-sidebar-aliases .link-list-item';