diff --git a/ui/admin/tests/acceptance/auth-methods/read-test.js b/ui/admin/tests/acceptance/auth-methods/read-test.js index 0b3fd0738..04d2c35f6 100644 --- a/ui/admin/tests/acceptance/auth-methods/read-test.js +++ b/ui/admin/tests/acceptance/auth-methods/read-test.js @@ -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, @@ -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); @@ -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); @@ -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); @@ -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); @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/ui/admin/tests/acceptance/auth-methods/selectors.js b/ui/admin/tests/acceptance/auth-methods/selectors.js index 2c4be3fd2..aae56bcb5 100644 --- a/ui/admin/tests/acceptance/auth-methods/selectors.js +++ b/ui/admin/tests/acceptance/auth-methods/selectors.js @@ -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'; @@ -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]'; @@ -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]'; @@ -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]'; @@ -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`; diff --git a/ui/admin/tests/acceptance/auth-methods/update-test.js b/ui/admin/tests/acceptance/auth-methods/update-test.js index 6458bb141..dda2abea6 100644 --- a/ui/admin/tests/acceptance/auth-methods/update-test.js +++ b/ui/admin/tests/acceptance/auth-methods/update-test.js @@ -15,6 +15,8 @@ import { TYPE_AUTH_METHOD_OIDC, TYPE_AUTH_METHOD_LDAP, } from 'api/models/auth-method'; +import * as commonSelectors from 'admin/tests/helpers/selectors'; +import * as selectors from './selectors'; module('Acceptance | auth-methods | update', function (hooks) { setupApplicationTest(hooks); @@ -23,40 +25,6 @@ module('Acceptance | auth-methods | update', function (hooks) { let featuresService; - const BUTTON_SELECTOR = '.rose-form-actions [type="button"]'; - const SAVE_BTN_SELECTOR = '.rose-form-actions [type="submit"]'; - const NAME_INPUT_SELECTOR = '[name="name"]'; - const URLS_INPUT_SELECTOR = '[name="urls"]'; - const DESC_INPUT_SELECTOR = '[name="description"]'; - const ERROR_MSG_SELECTOR = - '[data-test-toast-notification] .hds-alert__description'; - const FIELD_ERROR_TEXT_SELECTOR = '.hds-form-error__message'; - const CERTIFICATES_REMOVE_BTN_SELECTOR = - '[name="certificates"] [data-test-remove-button]'; - const CERTIFICATES_BTN_SELECTOR = '[name="certificates"] button'; - const CERTIFICATES_INPUT_SELECTOR = '[name="certificates"] textarea'; - const IDP_CERTS_INPUT_SELECTOR = '[name="idp_ca_certs"] textarea'; - const IDP_CERTS_REMOVE_BTN_SELECTOR = - '[name="idp_ca_certs"] [data-test-remove-button]'; - const IDP_CERTS_BTN_SELECTOR = '[name="idp_ca_certs"] button'; - - const ALLOWED_AUDIENCES_REMOVE_BTN_SELECTOR = - '[name="allowed_audiences"] [data-test-remove-button]'; - const ALLOWED_AUDIENCES_BTN_SELECTOR = '[name="allowed_audiences"] button'; - const ALLOWED_AUDIENCES_INPUT_SELECTOR = '[name="allowed_audiences"] input'; - - const CLAIMS_SCOPES_REMOVE_BTN_SELECTOR = - '[name="claims_scopes"] [data-test-remove-button]'; - const CLAIMS_SCOPES_BTN_SELECTOR = '[name="claims_scopes"] button'; - const CLAIMS_SCOPES_INPUT_SELECTOR = '[name="claims_scopes"] input'; - const TOGGLE_SELECTOR = '[name="prompts"]'; - - const SIGNING_ALGORITHMS_REMOVE_BTN_SELECTOR = - '[data-test-remove-option-button]'; - const SIGNING_ALGORITHMS_INPUT_SELECTOR = - '.list-wrapper-field tbody tr:last-child select'; - const SIGNING_ALGORITHMS_ADD_BTN_SELECTOR = '[data-test-add-option-button]'; - const instances = { scopes: { global: null, @@ -101,14 +69,19 @@ module('Acceptance | auth-methods | update', function (hooks) { test('can update an auth method and save changes', async function (assert) { await visit(urls.authMethods); - await click(`[href="${urls.authMethod}"]`); - await click(BUTTON_SELECTOR, 'Activate edit mode'); - await fillIn(NAME_INPUT_SELECTOR, 'update name'); - await click(SAVE_BTN_SELECTOR); + await click(commonSelectors.HREF(urls.authMethod)); + + await click(commonSelectors.EDIT_BTN); + await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE); + await fillIn( + commonSelectors.FIELD_DESCRIPTION, + commonSelectors.FIELD_DESCRIPTION_VALUE, + ); + await click(commonSelectors.SAVE_BTN); assert.strictEqual( this.server.schema.authMethods.first().name, - 'update name', + commonSelectors.FIELD_NAME_VALUE, ); }); @@ -119,164 +92,262 @@ module('Acceptance | auth-methods | update', function (hooks) { }); await visit(urls.authMethods); - await click(`[href="${urls.authMethods}/${instances.authMethod.id}"]`); - await click(BUTTON_SELECTOR, 'Activate edit mode'); - const name = 'oidc name'; - await fillIn(NAME_INPUT_SELECTOR, name); - await fillIn(DESC_INPUT_SELECTOR, 'description'); - await fillIn('[name="issuer"]', 'issuer'); - await fillIn('[name="client_id"]', 'client_id'); - await fillIn('[name="client_secret"]', 'client_secret'); + await click( + commonSelectors.HREF(`${urls.authMethods}/${instances.authMethod.id}`), + ); + await click(commonSelectors.EDIT_BTN); + + await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE); + await fillIn( + commonSelectors.FIELD_DESCRIPTION, + commonSelectors.FIELD_DESCRIPTION_VALUE, + ); + await fillIn(selectors.FIELD_ISSUER, selectors.FIELD_ISSUER_VALUE); + await fillIn(selectors.FIELD_CLIENT_ID, selectors.FIELD_CLIENT_ID_VALUE); + await fillIn( + selectors.FIELD_CLIENT_SECRET, + selectors.FIELD_CLIENT_SECRET_VALUE, + ); // Remove all signing algorithms - let removeButtons = findAll(SIGNING_ALGORITHMS_REMOVE_BTN_SELECTOR); + let removeButtons = findAll(selectors.FIELD_SIGNING_ALGORITHMS_DELETE_BTN); for (const element of removeButtons) { await click(element); } - await select(SIGNING_ALGORITHMS_INPUT_SELECTOR, 'RS384'); - await click(SIGNING_ALGORITHMS_ADD_BTN_SELECTOR); + + await select( + selectors.FIELD_SIGNING_ALGORITHMS, + selectors.FIELD_SIGNING_ALGORITHMS_VALUE, + ); + await click(selectors.FIELD_SIGNING_ALGORITHMS_ADD_BTN); // Remove all allowed audiences - const allowedAudiencesList = findAll(ALLOWED_AUDIENCES_REMOVE_BTN_SELECTOR); + const allowedAudiencesList = findAll( + selectors.FIELD_ALLOWED_AUDIENCES_DELETE_BTN, + ); for (const element of allowedAudiencesList) { await click(element); } - await fillIn(ALLOWED_AUDIENCES_INPUT_SELECTOR, 'allowed_audiences'); - await click(ALLOWED_AUDIENCES_BTN_SELECTOR, 'allowed_audiences'); + + await fillIn( + selectors.FIELD_ALLOWED_AUDIENCES, + selectors.FIELD_ALLOWED_AUDIENCES_VALUE, + ); + await click(selectors.FIELD_ALLOWED_AUDIENCES_ADD_BTN); // Remove all claims scopes const claimsScopeList = await Promise.all( - findAll(CLAIMS_SCOPES_REMOVE_BTN_SELECTOR), + findAll(selectors.FIELD_CLAIMS_SCOPES_DELETE_BTN), ); for (const element of claimsScopeList) { await click(element); } - await fillIn(CLAIMS_SCOPES_INPUT_SELECTOR, 'claims_scopes'); - await click(CLAIMS_SCOPES_BTN_SELECTOR, 'allowed_audiences'); + await fillIn( + selectors.FIELD_CLAIMS_SCOPES, + selectors.FIELD_CLAIMS_SCOPES_VALUE, + ); + await click(selectors.FIELD_CLAIMS_SCOPES_ADD_BTN); // Remove all claim maps const claimMaps = await Promise.all( - findAll('[name="account_claim_maps"] [data-test-remove-button]'), + findAll(selectors.FIELD_ACCOUNT_CLAIM_MAPS_DELETE_BTN), ); for (const element of claimMaps) { await click(element); } await fillIn( - '[name="account_claim_maps"] tbody td:nth-of-type(1) input', - 'from_claim', + selectors.FIELD_ACCOUNT_CLAIM_MAPS_FROM_CLAIM, + selectors.FIELD_ACCOUNT_CLAIM_MAPS_FROM_CLAIM_VALUE, ); - await select( - '[name="account_claim_maps"] tbody td:nth-of-type(2) select', - 'email', + selectors.FIELD_ACCOUNT_CLAIM_MAPS_TO_CLAIM, + selectors.FIELD_ACCOUNT_CLAIM_MAPS_TO_CLAIM_VALUE, ); - await click('[name="account_claim_maps"] button'); + await click(selectors.FIELD_ACCOUNT_CLAIM_MAPS_ADD_BTN); // Remove all certificates - const certificatesList = findAll(IDP_CERTS_REMOVE_BTN_SELECTOR); + const certificatesList = findAll(selectors.FIELD_IDP_CERTS_DELETE_BTN); for (const element of certificatesList) { await click(element); } - await fillIn(IDP_CERTS_INPUT_SELECTOR, 'certificates'); - await click(IDP_CERTS_BTN_SELECTOR); - await fillIn('[name="max_age"]', '5'); - await fillIn('[name="api_url_prefix"]', 'api_url_prefix'); - await click(TOGGLE_SELECTOR); - await click('.rose-form-actions [type="submit"]'); - const authMethod = this.server.schema.authMethods.findBy({ name }); + await fillIn(selectors.FIELD_IDP_CERTS, selectors.FIELD_IDP_CERTS_VALUE); + await click(selectors.FIELD_IDP_CERTS_ADD_BTN); + await fillIn(selectors.FIELD_MAX_AGE, selectors.FIELD_MAX_AGE_VALUE); + await fillIn( + selectors.FIELD_API_URL_PREFIX, + selectors.FIELD_API_URL_PREFIX_VALUE, + ); - assert.strictEqual(authMethod.name, name); - assert.strictEqual(authMethod.description, 'description'); - assert.strictEqual(authMethod.attributes.issuer, 'issuer'); - assert.strictEqual(authMethod.attributes.client_id, 'client_id'); - assert.deepEqual(authMethod.attributes.signing_algorithms, ['RS384']); - assert.deepEqual(authMethod.attributes.allowed_audiences, [ - 'allowed_audiences', + await click(selectors.FIELD_PROMPTS); + await click(commonSelectors.SAVE_BTN); + + const authMethod = this.server.schema.authMethods.findBy({ + name: commonSelectors.FIELD_NAME_VALUE, + }); + + assert.strictEqual(authMethod.name, commonSelectors.FIELD_NAME_VALUE); + assert.strictEqual( + authMethod.description, + commonSelectors.FIELD_DESCRIPTION_VALUE, + ); + assert.strictEqual( + authMethod.attributes.issuer, + selectors.FIELD_ISSUER_VALUE, + ); + assert.strictEqual( + authMethod.attributes.client_id, + selectors.FIELD_CLIENT_ID_VALUE, + ); + assert.deepEqual(authMethod.attributes.signing_algorithms, [ + selectors.FIELD_SIGNING_ALGORITHMS_VALUE, + ]); + assert.deepEqual(authMethod.attributes.allowed_audiences, [ + selectors.FIELD_ALLOWED_AUDIENCES_VALUE, + ]); + assert.deepEqual(authMethod.attributes.claims_scopes, [ + selectors.FIELD_CLAIMS_SCOPES_VALUE, ]); - assert.deepEqual(authMethod.attributes.claims_scopes, ['claims_scopes']); assert.deepEqual(authMethod.attributes.account_claim_maps, [ 'from_claim=email', ]); - assert.deepEqual(authMethod.attributes.idp_ca_certs, ['certificates']); - assert.strictEqual(authMethod.attributes.max_age, 5); - assert.strictEqual(authMethod.attributes.api_url_prefix, 'api_url_prefix'); + assert.deepEqual(authMethod.attributes.idp_ca_certs, [ + selectors.FIELD_IDP_CERTS_VALUE, + ]); + assert.strictEqual( + authMethod.attributes.max_age, + parseInt(selectors.FIELD_MAX_AGE_VALUE), + ); + assert.strictEqual( + authMethod.attributes.api_url_prefix, + selectors.FIELD_API_URL_PREFIX_VALUE, + ); assert.deepEqual(authMethod.attributes.prompts, ['none']); }); test('can update an ldap auth method and save changes', async function (assert) { featuresService.enable('ldap-auth-methods'); await visit(urls.authMethods); - const name = 'ldap auth method'; - await click(`[href="${urls.ldapAuthMethod}"]`); - await click(BUTTON_SELECTOR, 'Activate edit mode'); - await fillIn(NAME_INPUT_SELECTOR, name); - await fillIn(DESC_INPUT_SELECTOR, 'description'); - await fillIn('[name="urls"]', 'url1,url2'); - await click('[name="certificates"] .hds-button--color-critical'); + await click(commonSelectors.HREF(urls.ldapAuthMethod)); + await click(commonSelectors.EDIT_BTN); + await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE); + await fillIn( + commonSelectors.FIELD_DESCRIPTION, + commonSelectors.FIELD_DESCRIPTION_VALUE, + ); + await fillIn(selectors.FIELD_URLS, selectors.FIELD_URLS_VALUE); + await click(selectors.FIELD_CERTIFICATES_DELETE_BTN); - // Remove certificate - const certificatesList = findAll(CERTIFICATES_REMOVE_BTN_SELECTOR); + // Certificates + await fillIn( + selectors.FIELD_CERTIFICATES, + selectors.FIELD_CERTIFICATES_VALUE, + ); + await click(selectors.FIELD_CERTIFICATES_ADD_BTN); + + await click(selectors.FIELD_START_TLS); + await click(selectors.FIELD_INSECURE_TLS); + await fillIn(selectors.FIELD_BIND_DN, selectors.FIELD_BIND_DN_VALUE); + await fillIn(selectors.FIELD_UPN_DOMAIN, selectors.FIELD_UPN_DOMAIN_VALUE); + await click(selectors.FIELD_DISCOVER_DN); + await click(selectors.FIELD_ANON_GROUP_SEARCH); + await fillIn(selectors.FIELD_USER_DN, selectors.FIELD_USER_DN_VALUE); + await fillIn(selectors.FIELD_USER_ATTR, selectors.FIELD_USER_ATTR_VALUE); + await fillIn( + selectors.FIELD_USER_FILTER, + selectors.FIELD_USER_FILTER_VALUE, + ); - for (const element of certificatesList) { - await click(element); - } - await fillIn(CERTIFICATES_INPUT_SELECTOR, 'certificate'); - await click(CERTIFICATES_BTN_SELECTOR); - await click('[name="start_tls"]'); - await click('[name="insecure_tls"]'); - await fillIn('[name="bind_dn"]', 'bind dn'); - await fillIn('[name="upn_domain"]', 'upn domain'); - await click('[name="discover_dn"]'); - await click('[name="anon_group_search"]'); - await fillIn('[name="user_dn"]', 'user dn'); - await fillIn('[name="user_attr"]', 'user attr'); - await fillIn('[name="user_filter"]', 'user filter'); // Remove all attribute maps const attributeMaps = await Promise.all( - findAll('[name="account_attribute_maps"] .hds-button--color-critical'), + findAll(selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_DELETE_BTN), ); + for (const element of attributeMaps) { await click(element); } - await fillIn('[name="account_attribute_maps"] input', 'attribute'); - await select('[name="account_attribute_maps"] select', 'email'); - await click('[name="account_attribute_maps"] button'); - await fillIn('[name="group_dn"]', 'group dn'); - await fillIn('[name="group_attr"]', 'group attr'); - await fillIn('[name="group_filter"]', 'group filter'); - await click('[name="enable_groups"]'); - await click('[name="use_token_groups"]'); - await click(SAVE_BTN_SELECTOR); - const ldapAuthMethod = this.server.schema.authMethods.findBy({ name }); - assert.strictEqual(ldapAuthMethod.name, name); - assert.strictEqual(ldapAuthMethod.description, 'description'); - assert.deepEqual(ldapAuthMethod.attributes.urls, ['url1', 'url2']); - assert.deepEqual(ldapAuthMethod.attributes.certificates, ['certificate']); + await fillIn( + selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_FROM, + selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_FROM_VALUE, + ); + await select( + selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_TO, + selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_TO_VALUE, + ); + await click(selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_ADD_BTN); + await fillIn(selectors.FIELD_GROUP_DN, selectors.FIELD_GROUP_DN_VALUE); + await fillIn(selectors.FIELD_GROUP_ATTR, selectors.FIELD_GROUP_ATTR_VALUE); + await fillIn( + selectors.FIELD_GROUP_FILTER, + selectors.FIELD_GROUP_FILTER_VALUE, + ); + await click(selectors.FIELD_ENABLE_GROUPS); + await click(selectors.FIELD_USE_TOKEN_GROUPS); + await click(commonSelectors.SAVE_BTN); + + const ldapAuthMethod = this.server.schema.authMethods.findBy({ + name: commonSelectors.FIELD_NAME_VALUE, + }); + assert.strictEqual(ldapAuthMethod.name, commonSelectors.FIELD_NAME_VALUE); + assert.strictEqual( + ldapAuthMethod.description, + commonSelectors.FIELD_DESCRIPTION_VALUE, + ); + assert.deepEqual( + ldapAuthMethod.attributes.urls, + selectors.FIELD_URLS_VALUE.split(','), + ); + assert.deepEqual(ldapAuthMethod.attributes.certificates, [ + selectors.FIELD_CERTIFICATES_VALUE, + ]); assert.true(ldapAuthMethod.attributes.start_tls); assert.true(ldapAuthMethod.attributes.insecure_tls); - assert.strictEqual(ldapAuthMethod.attributes.bind_dn, 'bind dn'); - assert.strictEqual(ldapAuthMethod.attributes.upn_domain, 'upn domain'); + assert.strictEqual( + ldapAuthMethod.attributes.bind_dn, + selectors.FIELD_BIND_DN_VALUE, + ); + assert.strictEqual( + ldapAuthMethod.attributes.upn_domain, + selectors.FIELD_UPN_DOMAIN_VALUE, + ); assert.true(ldapAuthMethod.attributes.discover_dn); assert.true(ldapAuthMethod.attributes.anon_group_search); - assert.strictEqual(ldapAuthMethod.attributes.user_dn, 'user dn'); - assert.strictEqual(ldapAuthMethod.attributes.user_attr, 'user attr'); - assert.strictEqual(ldapAuthMethod.attributes.user_filter, 'user filter'); + assert.strictEqual( + ldapAuthMethod.attributes.user_dn, + selectors.FIELD_USER_DN_VALUE, + ); + assert.strictEqual( + ldapAuthMethod.attributes.user_attr, + selectors.FIELD_USER_ATTR_VALUE, + ); + assert.strictEqual( + ldapAuthMethod.attributes.user_filter, + selectors.FIELD_USER_FILTER_VALUE, + ); assert.deepEqual(ldapAuthMethod.attributes.account_attribute_maps, [ - 'attribute=email', + `${selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_FROM_VALUE}=${selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_TO_VALUE}`, ]); - assert.strictEqual(ldapAuthMethod.attributes.group_dn, 'group dn'); - assert.strictEqual(ldapAuthMethod.attributes.group_attr, 'group attr'); - assert.strictEqual(ldapAuthMethod.attributes.group_filter, 'group filter'); + assert.strictEqual( + ldapAuthMethod.attributes.group_dn, + selectors.FIELD_GROUP_DN_VALUE, + ); + assert.strictEqual( + ldapAuthMethod.attributes.group_attr, + selectors.FIELD_GROUP_ATTR_VALUE, + ); + assert.strictEqual( + ldapAuthMethod.attributes.group_filter, + selectors.FIELD_GROUP_FILTER_VALUE, + ); assert.false(ldapAuthMethod.attributes.enable_groups); assert.true(ldapAuthMethod.attributes.use_token_groups); }); @@ -284,9 +355,9 @@ module('Acceptance | auth-methods | update', function (hooks) { test('can update an auth method and cancel changes', async function (assert) { await visit(urls.authMethod); - await click(BUTTON_SELECTOR, 'Activate edit mode'); - await fillIn(NAME_INPUT_SELECTOR, 'update name'); - await click(BUTTON_SELECTOR, 'Cancel'); + await click(commonSelectors.EDIT_BTN); + await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE); + await click(commonSelectors.CANCEL_BTN); assert.notEqual(this.server.schema.authMethods.first().name, 'update name'); }); @@ -298,12 +369,21 @@ module('Acceptance | auth-methods | update', function (hooks) { const ldapAuthMethod = this.server.schema.authMethods.findBy({ name }); const { certificates, account_attribute_maps } = ldapAuthMethod.attributes; - await click(`[href="${urls.ldapAuthMethod}"]`); - await click(BUTTON_SELECTOR, 'Activate edit mode'); - await fillIn('[name="certificates"] textarea', 'cert123'); - await fillIn('[name="account_attribute_maps"] input', 'attribute'); - await select('[name="account_attribute_maps"] select', 'email'); - await click(BUTTON_SELECTOR, 'Cancel'); + await click(commonSelectors.HREF(urls.ldapAuthMethod)); + await click(commonSelectors.EDIT_BTN); + await fillIn( + selectors.FIELD_CERTIFICATES, + selectors.FIELD_CERTIFICATES_VALUE, + ); + await fillIn( + selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_FROM, + selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_FROM_VALUE, + ); + await select( + selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_TO, + selectors.FIELD_ACCOUNT_ATTRIBUTE_MAPS_TO_VALUE, + ); + await click(commonSelectors.CANCEL_BTN); assert.deepEqual(ldapAuthMethod.attributes.certificates, certificates); assert.deepEqual( @@ -319,9 +399,9 @@ module('Acceptance | auth-methods | update', function (hooks) { ); await visit(urls.authMethods); - await click(`[href="${urls.authMethod}"]`); + await click(commonSelectors.HREF(urls.authMethod)); - assert.dom(BUTTON_SELECTOR).doesNotExist(); + assert.dom(commonSelectors.EDIT_BTN).isNotVisible(); }); test('cannot make changes to an existing ldap auth method without proper authorization', async function (assert) { @@ -332,12 +412,14 @@ module('Acceptance | auth-methods | update', function (hooks) { ); await visit(urls.authMethods); - await click(`[href="${urls.ldapAuthMethod}"]`); + await click(commonSelectors.HREF(urls.ldapAuthMethod)); - assert.dom(BUTTON_SELECTOR).doesNotExist(); + assert.dom(commonSelectors.EDIT_BTN).isNotVisible(); }); test('saving an existing auth method with invalid fields displays error messages', async function (assert) { + const errorMessage = 'The request was invalid.'; + const errorDescription = 'Name is required.'; this.server.patch('/auth-methods/:id', () => { return new Response( 400, @@ -345,12 +427,12 @@ module('Acceptance | auth-methods | update', function (hooks) { { status: 400, code: 'invalid_argument', - message: 'The request was invalid.', + message: errorMessage, details: { request_fields: [ { name: 'name', - description: 'Name is required.', + description: errorDescription, }, ], }, @@ -359,18 +441,20 @@ module('Acceptance | auth-methods | update', function (hooks) { }); await visit(urls.authMethods); - await click(`[href="${urls.authMethod}"]`); - await click(BUTTON_SELECTOR, 'Activate edit mode'); - await fillIn(NAME_INPUT_SELECTOR, 'existing auth method'); - await click(SAVE_BTN_SELECTOR); + await click(commonSelectors.HREF(urls.authMethod)); + await click(commonSelectors.EDIT_BTN); + await fillIn(commonSelectors.FIELD_NAME, commonSelectors.FIELD_NAME_VALUE); + await click(commonSelectors.SAVE_BTN); await a11yAudit(); - assert.dom(ERROR_MSG_SELECTOR).hasText('The request was invalid.'); - assert.dom('.hds-form-error__message').hasText('Name is required.'); + assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText(errorMessage); + assert.dom(commonSelectors.FIELD_NAME_ERROR).hasText(errorDescription); }); test('saving an existing ldap auth method with invalid fields displays error messages', async function (assert) { featuresService.enable('ldap-auth-methods'); + const errorMessage = 'The request was invalid.'; + const errorDescription = 'URL field is required'; this.server.patch('/auth-methods/:id', () => { return new Response( 400, @@ -378,12 +462,12 @@ module('Acceptance | auth-methods | update', function (hooks) { { status: 400, code: 'invalid_argument', - message: 'The request was invalid.', + message: errorMessage, details: { request_fields: [ { name: 'urls', - description: 'scheme in url "" is not either ldap or ldaps', + description: errorDescription, }, ], }, @@ -392,14 +476,13 @@ module('Acceptance | auth-methods | update', function (hooks) { }); await visit(urls.authMethods); - await click(`[href="${urls.ldapAuthMethod}"]`); - await click(BUTTON_SELECTOR, 'Activate edit mode'); - await fillIn(URLS_INPUT_SELECTOR, ''); - await click(SAVE_BTN_SELECTOR); + await click(commonSelectors.HREF(urls.ldapAuthMethod)); + await click(commonSelectors.EDIT_BTN); + await fillIn(selectors.FIELD_URLS, ''); + await click(commonSelectors.SAVE_BTN); await a11yAudit(); - assert.dom(ERROR_MSG_SELECTOR).hasText('The request was invalid.'); - assert - .dom(FIELD_ERROR_TEXT_SELECTOR) - .hasText('scheme in url "" is not either ldap or ldaps'); + + assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText(errorMessage); + assert.dom(selectors.FIELD_ERROR).hasText(errorDescription); }); });