test: 💍 refactor targets manage alias test selectors (#2921)
✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16437
This commit is contained in:
1 parent
aa18f599ce
commit
d93a0c170c
2 files changed
+26
-33
No files matched your search
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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';
|
||||
|
||||
Reference in new issue
Block a user