Skip to content

Commit

Permalink
Refactor auth methods red test selectors (#2656)
Browse files Browse the repository at this point in the history
* Refactor auth-methods list acceptance test selectors
  • Loading branch information
calcaide authored Jan 24, 2025
1 parent 064375d commit 1e2134b
Show file tree
Hide file tree
Showing 3 changed files with 302 additions and 194 deletions.
73 changes: 40 additions & 33 deletions ui/admin/tests/acceptance/auth-methods/read-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@ import {
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_PASSWORD,
} from 'api/models/auth-method';
import * as commonSelectors from 'admin/tests/helpers/selectors';
import * as selectors from './selectors';

module('Acceptance | auth-methods | read', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);

const AUTH_LINK_SELECTOR = (id) =>
`tbody [data-test-auth-methods-table-row="${id}"] a`;
const AUTH_TYPE_SELECTOR = (id) =>
`tbody [data-test-auth-methods-table-row="${id}"] .hds-table__td:nth-child(2)`;
const AUTH_ACTIONS_SELECTOR = (id) =>
`tbody [data-test-auth-methods-table-row="${id}"] .hds-table__td:last-child .hds-dropdown`;

const instances = {
scopes: {
global: null,
Expand Down Expand Up @@ -75,7 +70,7 @@ module('Acceptance | auth-methods | read', function (hooks) {
test('visiting auth methods in org scope', async function (assert) {
await visit(urls.orgScope);

await click(`[href="${urls.orgAuthMethods}"]`);
await click(commonSelectors.HREF(urls.orgAuthMethods));
await a11yAudit();

assert.strictEqual(currentURL(), urls.orgAuthMethods);
Expand All @@ -84,7 +79,7 @@ module('Acceptance | auth-methods | read', function (hooks) {
test('visiting auth methods in global scope', async function (assert) {
await visit(urls.globalScope);

await click(`[href="${urls.globalAuthMethods}"]`);
await click(commonSelectors.HREF(urls.globalAuthMethods));
await a11yAudit();

assert.strictEqual(currentURL(), urls.globalAuthMethods);
Expand All @@ -93,16 +88,18 @@ module('Acceptance | auth-methods | read', function (hooks) {
test('can navigate to an auth method form in org scope', async function (assert) {
await visit(urls.orgScope);

await click(`[href="${urls.orgAuthMethods}"]`);
await click(commonSelectors.HREF(urls.orgAuthMethods));

assert
.dom(AUTH_TYPE_SELECTOR(instances.passwordAuthMethodOrg.id))
.dom(selectors.TABLE_ROW_TYPE(instances.passwordAuthMethodOrg.id))
.hasText('Password');
assert
.dom(AUTH_ACTIONS_SELECTOR(instances.passwordAuthMethodOrg.id))
.exists();
.dom(selectors.TABLE_ACTION_DROPDOWN(instances.passwordAuthMethodOrg.id))
.isVisible();

await click(AUTH_LINK_SELECTOR(instances.passwordAuthMethodOrg.id));
await click(
selectors.TABLE_ROW_NAME_LINK(instances.passwordAuthMethodOrg.id),
);
await a11yAudit();

assert.strictEqual(currentURL(), urls.passwordAuthMethodOrg);
Expand All @@ -111,16 +108,18 @@ module('Acceptance | auth-methods | read', function (hooks) {
test('can navigate to an auth method form in global scope', async function (assert) {
await visit(urls.globalScope);

await click(`[href="${urls.globalAuthMethods}"]`);
await click(commonSelectors.HREF(urls.globalAuthMethods));

assert
.dom(AUTH_TYPE_SELECTOR(instances.oidcAuthMethodGlobal.id))
.dom(selectors.TABLE_ROW_TYPE(instances.oidcAuthMethodGlobal.id))
.hasText('OIDC');
assert
.dom(AUTH_ACTIONS_SELECTOR(instances.oidcAuthMethodGlobal.id))
.exists();
.dom(selectors.TABLE_ACTION_DROPDOWN(instances.oidcAuthMethodGlobal.id))
.isVisible();

await click(AUTH_LINK_SELECTOR(instances.oidcAuthMethodGlobal.id));
await click(
selectors.TABLE_ROW_NAME_LINK(instances.oidcAuthMethodGlobal.id),
);
await a11yAudit();

assert.strictEqual(currentURL(), urls.oidcAuthMethodGlobal);
Expand All @@ -133,11 +132,11 @@ module('Acceptance | auth-methods | read', function (hooks) {
);
await visit(urls.orgScope);

await click(`[href="${urls.orgAuthMethods}"]`);
await click(commonSelectors.HREF(urls.orgAuthMethods));

assert
.dom(AUTH_LINK_SELECTOR(instances.passwordAuthMethodOrg.id))
.doesNotExist();
.dom(selectors.TABLE_ROW_NAME_LINK(instances.passwordAuthMethodOrg.id))
.isNotVisible();
});

test('cannot navigate to an auth method form without proper authorization in global scope', async function (assert) {
Expand All @@ -147,11 +146,11 @@ module('Acceptance | auth-methods | read', function (hooks) {
);
await visit(urls.globalScope);

await click(`[href="${urls.globalAuthMethods}"]`);
await click(commonSelectors.HREF(urls.globalAuthMethods));

assert
.dom(AUTH_LINK_SELECTOR(instances.oidcAuthMethodGlobal.id))
.doesNotExist();
.dom(selectors.TABLE_ROW_NAME_LINK(instances.oidcAuthMethodGlobal.id))
.isNotVisible();
});

test('cannot navigate to an ldap auth method form in global scope', async function (assert) {
Expand All @@ -161,13 +160,17 @@ module('Acceptance | auth-methods | read', function (hooks) {
});
await visit(urls.globalScope);

await click(`[href="${urls.globalAuthMethods}"]`);
await click(commonSelectors.HREF(urls.globalAuthMethods));

assert.dom(AUTH_LINK_SELECTOR(instances.ldapAuthMethod.id)).doesNotExist();
assert.dom(AUTH_TYPE_SELECTOR(instances.ldapAuthMethod.id)).hasText('LDAP');
assert
.dom(AUTH_ACTIONS_SELECTOR(instances.ldapAuthMethod.id))
.dom(selectors.TABLE_ROW_NAME_LINK(instances.ldapAuthMethod.id))
.doesNotExist();
assert
.dom(selectors.TABLE_ROW_TYPE(instances.ldapAuthMethod.id))
.hasText('LDAP');
assert
.dom(selectors.TABLE_ACTION_DROPDOWN(instances.ldapAuthMethod.id))
.isNotVisible();
});

test('cannot navigate to an ldap auth method form in org scope', async function (assert) {
Expand All @@ -177,13 +180,17 @@ module('Acceptance | auth-methods | read', function (hooks) {
});
await visit(urls.orgScope);

await click(`[href="${urls.orgAuthMethods}"]`);
await click(commonSelectors.HREF(urls.orgAuthMethods));

assert.dom(AUTH_LINK_SELECTOR(instances.ldapAuthMethod.id)).doesNotExist();
assert.dom(AUTH_TYPE_SELECTOR(instances.ldapAuthMethod.id)).hasText('LDAP');
assert
.dom(AUTH_ACTIONS_SELECTOR(instances.ldapAuthMethod.id))
.dom(selectors.TABLE_ROW_NAME_LINK(instances.ldapAuthMethod.id))
.doesNotExist();
assert
.dom(selectors.TABLE_ROW_TYPE(instances.ldapAuthMethod.id))
.hasText('LDAP');
assert
.dom(selectors.TABLE_ACTION_DROPDOWN(instances.ldapAuthMethod.id))
.isNotVisible();
});

test('users can navigate to auth method and incorrect url autocorrects', async function (assert) {
Expand Down
18 changes: 18 additions & 0 deletions ui/admin/tests/acceptance/auth-methods/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ export const FIELD_CLIENT_SECRET_VALUE = 'Client secret value';
export const FIELD_SIGNING_ALGORITHMS = '[name=signing_algorithms] select';
export const FIELD_SIGNING_ALGORITHMS_VALUE = 'RS384';
export const FIELD_SIGNING_ALGORITHMS_ADD_BTN = '[data-test-add-option-button]';
export const FIELD_SIGNING_ALGORITHMS_DELETE_BTN =
'[name=signing_algorithms] tbody td:last-child button[aria-label=Remove]';
export const FIELD_ALLOWED_AUDIENCES = '[name=allowed_audiences] input';
export const FIELD_ALLOWED_AUDIENCES_VALUE = 'Allowed audiences';
export const FIELD_ALLOWED_AUDIENCES_ADD_BTN =
'[name=allowed_audiences] button';
export const FIELD_ALLOWED_AUDIENCES_DELETE_BTN =
'[name=allowed_audiences] tbody td:last-child button[aria-label=Remove]';
export const FIELD_CLAIMS_SCOPES = '[name=claims_scopes] input';
export const FIELD_CLAIMS_SCOPES_VALUE = 'Claim scopes';
export const FIELD_CLAIMS_SCOPES_ADD_BTN = '[name=claims_scopes] button';
export const FIELD_CLAIMS_SCOPES_DELETE_BTN =
'[name=claims_scopes] tbody td:last-child button[aria-label=Remove]';
export const FIELD_ACCOUNT_CLAIM_MAPS_FROM_CLAIM =
'[name=account_claim_maps] tbody td:nth-of-type(1) input';
export const FIELD_ACCOUNT_CLAIM_MAPS_FROM_CLAIM_VALUE = 'from_claim';
Expand All @@ -27,9 +33,13 @@ export const FIELD_ACCOUNT_CLAIM_MAPS_TO_CLAIM =
export const FIELD_ACCOUNT_CLAIM_MAPS_TO_CLAIM_VALUE = 'email';
export const FIELD_ACCOUNT_CLAIM_MAPS_ADD_BTN =
'[name=account_claim_maps] button';
export const FIELD_ACCOUNT_CLAIM_MAPS_DELETE_BTN =
'[name=account_claim_maps] tbody td:last-child button[aria-label=Remove]';
export const FIELD_IDP_CERTS = '[name=idp_ca_certs] textarea';
export const FIELD_IDP_CERTS_VALUE = 'IDP certificates';
export const FIELD_IDP_CERTS_ADD_BTN = '[name=idp_ca_certs] button';
export const FIELD_IDP_CERTS_DELETE_BTN =
'[name=idp_ca_certs] tbody td:last-child button[aria-label=Remove]';
export const FIELD_MAX_AGE = '[name=max_age]';
export const FIELD_MAX_AGE_VALUE = '5';
export const FIELD_API_URL_PREFIX = '[name=api_url_prefix]';
Expand All @@ -43,6 +53,8 @@ export const FIELD_URLS_VALUE = 'url1,url2';
export const FIELD_CERTIFICATES = '[name=certificates] textarea';
export const FIELD_CERTIFICATES_VALUE = 'certificate';
export const FIELD_CERTIFICATES_ADD_BTN = '[name=certificates] button';
export const FIELD_CERTIFICATES_DELETE_BTN =
'[name="certificates"] button[aria-label=Remove]';
export const FIELD_CLIENT_CERTIFICATE = '[name=client_certificate]';
export const FIELD_CLIENT_CERTIFICATE_VALUE = 'Client certificate value';
export const FIELD_CLIENT_CERTIFICATE_KEY = '[name=client_certificate_key]';
Expand Down Expand Up @@ -72,6 +84,8 @@ export const FIELD_ACCOUNT_ATTRIBUTE_MAPS_TO =
export const FIELD_ACCOUNT_ATTRIBUTE_MAPS_TO_VALUE = 'email';
export const FIELD_ACCOUNT_ATTRIBUTE_MAPS_ADD_BTN =
'[name=account_attribute_maps] button';
export const FIELD_ACCOUNT_ATTRIBUTE_MAPS_DELETE_BTN =
'[name=account_attribute_maps] button[aria-label=Remove]';
export const FIELD_GROUP_DN = '[name=group_dn]';
export const FIELD_GROUP_DN_VALUE = 'Group dn value';
export const FIELD_GROUP_ATTR = '[name=group_attr]';
Expand All @@ -97,3 +111,7 @@ export const TABLE_ACTION_DROPDOWN = (authMethodId) =>
`tbody [data-test-auth-methods-table-row="${authMethodId}"] .hds-table__td:last-child .hds-dropdown button`;
export const TABLE_ACTION_DROPDOWN_MAKE_PRIMARY = (authMethodId) =>
`tbody tr[data-test-auth-methods-table-row="${authMethodId}"] td:last-child ul li:first-child button`;
export const TABLE_ROW_TYPE = (authMethodId) =>
`tbody [data-test-auth-methods-table-row="${authMethodId}"] .hds-table__td:nth-child(2)`;
export const TABLE_ROW_NAME_LINK = (authMethodId) =>
`tbody [data-test-auth-methods-table-row="${authMethodId}"] .hds-table__td:first-child a`;
Loading

0 comments on commit 1e2134b

Please sign in to comment.