Refactor test selectors within auth-methods oidc test (#2717)

* Refactor test selectors within auth-methods oidc test
This commit is contained in:
Carlos Alcaide Corvo authored and GitHub committed 2025-03-13 08:39:11 -07:00
1 parent d212cf7c40
commit 706981c231
2 files changed
+35 -28

No files matched your search

@@ -4,19 +4,14 @@
*/
import { module, test } from 'qunit';
import { visit, currentURL, click, find } from '@ember/test-helpers';
import { visit, currentURL, click } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
//import { Response } from 'miragejs';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { TYPE_AUTH_METHOD_OIDC } from 'api/models/auth-method';
import * as commonSelectors from 'admin/tests/helpers/selectors';
const CHANGE_STATE_SELECTOR = '[data-test-change-state] button:first-child';
const CHANGE_STATE_INPUT_CHECKED = '[data-test-change-state] input:checked';
const CHANGE_STATE_INPUT_SELECTOR = '[data-test-change-state]';
import * as selectors from './selectors';
module('Acceptance | auth-methods | oidc', function (hooks) {
setupApplicationTest(hooks);
@@ -55,42 +50,47 @@ module('Acceptance | auth-methods | oidc', function (hooks) {
test('visiting oidc auth method', async function (assert) {
await visit(urls.authMethod);
await a11yAudit();
assert.strictEqual(currentURL(), urls.authMethod);
});
test('can view oidc state', async function (assert) {
await visit(urls.authMethod);
await click(CHANGE_STATE_SELECTOR);
assert.strictEqual(
find(CHANGE_STATE_INPUT_CHECKED).value,
instances.authMethod.attributes.state,
);
await click(selectors.CHANGE_STATE_DROPDOWN);
assert
.dom(selectors.CHANGE_STATE_DROPDOWN_CHECKED)
.hasValue(instances.authMethod.attributes.state);
});
test('can update oidc state', async function (assert) {
const updateValue = 'inactive';
await visit(urls.authMethod);
await click(CHANGE_STATE_SELECTOR);
await click(`${CHANGE_STATE_INPUT_SELECTOR} input[value="${updateValue}"]`);
await click(selectors.CHANGE_STATE_DROPDOWN);
await click(selectors.CHANGE_STATE_DROPDOWN_STATE(updateValue));
const authMethod = this.server.schema.authMethods.findBy({
id: instances.authMethod.id,
});
assert.strictEqual(authMethod.attributes.state, updateValue);
});
test('can update oidc state to active-private', async function (assert) {
const updateValue = 'active-private';
await visit(urls.authMethod);
await click(CHANGE_STATE_SELECTOR);
await click(`${CHANGE_STATE_INPUT_SELECTOR} input[value="${updateValue}"]`);
await click(selectors.CHANGE_STATE_DROPDOWN);
await click(selectors.CHANGE_STATE_DROPDOWN_STATE(updateValue));
const authMethod = this.server.schema.authMethods.findBy({
id: instances.authMethod.id,
});
assert.strictEqual(
find(CHANGE_STATE_INPUT_CHECKED).value,
instances.authMethod.attributes.state,
);
assert
.dom(selectors.CHANGE_STATE_DROPDOWN_CHECKED)
.hasValue(instances.authMethod.attributes.state);
assert.strictEqual(authMethod.attributes.state, updateValue);
});
@@ -98,17 +98,17 @@ module('Acceptance | auth-methods | oidc', function (hooks) {
instances.authMethod.attributes.state = 'inactive';
const updateValue = 'active-public';
await visit(urls.authMethod);
await click(CHANGE_STATE_SELECTOR);
await click(`${CHANGE_STATE_INPUT_SELECTOR} input[value="${updateValue}"]`);
await click(selectors.CHANGE_STATE_DROPDOWN);
await click(selectors.CHANGE_STATE_DROPDOWN_STATE(updateValue));
const authMethod = this.server.schema.authMethods.findBy({
id: instances.authMethod.id,
});
assert.strictEqual(
find(CHANGE_STATE_INPUT_CHECKED).value,
instances.authMethod.attributes.state,
);
assert
.dom(selectors.CHANGE_STATE_DROPDOWN_CHECKED)
.hasValue(instances.authMethod.attributes.state);
assert.strictEqual(authMethod.attributes.state, updateValue);
});
@@ -117,3 +117,10 @@ 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`;
export const CHANGE_STATE_DROPDOWN =
'[data-test-change-state] button:first-child';
export const CHANGE_STATE_DROPDOWN_CHECKED =
'[data-test-change-state] input:checked';
export const CHANGE_STATE_DROPDOWN_STATE = (state) =>
`[data-test-change-state] input[value="${state}"]`;