-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor a11yAudit for auth-method list test #2520
base: main
Are you sure you want to change the base?
Changes from 6 commits
d72582c
a407f99
5c307e4
acf5161
7697c6b
796693b
160497f
a120dd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,16 @@ | |
*/ | ||
|
||
import { module, test } from 'qunit'; | ||
import { visit, click, waitFor, fillIn } from '@ember/test-helpers'; | ||
import { visit, click, waitFor, fillIn, currentURL } from '@ember/test-helpers'; | ||
import { setupApplicationTest } from 'ember-qunit'; | ||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; | ||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db'; | ||
import a11yAudit from 'ember-a11y-testing/test-support/audit'; | ||
import { | ||
currentSession, | ||
authenticateSession, | ||
// These are left here intentionally for future reference. | ||
//currentSession, | ||
//invalidateSession, | ||
} from 'ember-simple-auth/test-support'; | ||
import { Response } from 'miragejs'; | ||
import { | ||
TYPE_AUTH_METHOD_PASSWORD, | ||
TYPE_AUTH_METHOD_OIDC, | ||
|
@@ -47,6 +47,8 @@ module('Acceptance | auth-methods | list', function (hooks) { | |
globalScope: null, | ||
orgScope: null, | ||
authMethods: null, | ||
orgAuthMethods: null, | ||
globalAuthMethods: null, | ||
passwordAuthMethod: null, | ||
oidcAuthMethod: null, | ||
}; | ||
|
@@ -69,13 +71,75 @@ module('Acceptance | auth-methods | list', function (hooks) { | |
scope: instances.scopes.org, | ||
type: TYPE_AUTH_METHOD_OIDC, | ||
}); | ||
urls.globalScope = `/scopes/global/scopes`; | ||
urls.globalScope = `/scopes/global`; | ||
urls.orgScope = `/scopes/${instances.scopes.org.id}`; | ||
urls.authMethods = `/scopes/${instances.scopes.org.id}/auth-methods`; | ||
urls.globalAuthMethods = `${urls.globalScope}/auth-methods`; | ||
urls.orgAuthMethods = `${urls.orgScope}/auth-methods`; | ||
urls.passwordAuthMethod = `${urls.authMethods}/${instances.passwordAuthMethod.id}`; | ||
urls.oidcAuthMethod = `${urls.authMethods}/${instances.oidcAuthMethod.id}`; | ||
|
||
authenticateSession({}); | ||
authenticateSession({ username: 'admin' }); | ||
}); | ||
|
||
module('a11yAudit', function () { | ||
test.each('auth-methods', ['light', 'dark'], async function (assert, data) { | ||
assert.expect(0); | ||
currentSession().set('data.theme', data); | ||
await visit(urls.authMethods); | ||
|
||
// open new dropdown | ||
await click('.rose-layout-page-actions button'); | ||
await a11yAudit(); | ||
|
||
// open dropdown at last row | ||
await click('td:last-child button'); | ||
await a11yAudit(); | ||
|
||
// open primary filter | ||
await click('.hds-segmented-group div[name="primary"] div button'); | ||
await a11yAudit(); | ||
|
||
// check 'yes' | ||
await click( | ||
'.hds-segmented-group div[name="primary"] div:last-child input', | ||
); | ||
await a11yAudit(); | ||
|
||
// filter selected | ||
await click(FILTER_DROPDOWN_SELECTOR('type')); | ||
await click(`input[value="${TYPE_AUTH_METHOD_PASSWORD}"]`); | ||
await click(FILTER_APPLY_BUTTON_SELECTOR); | ||
await a11yAudit(); | ||
|
||
// "no results" message | ||
await fillIn( | ||
SEARCH_INPUT_SELECTOR, | ||
'fake auth method that does not exist', | ||
); | ||
await a11yAudit(); | ||
}); | ||
|
||
test('API error', async function (assert) { | ||
assert.expect(0); | ||
this.server.get('/auth-methods', () => { | ||
return new Response( | ||
418, | ||
{}, | ||
{ | ||
status: 418, | ||
code: "I'm a teapot", | ||
message: 'Ope, sorry about that!', | ||
}, | ||
); | ||
}); | ||
|
||
await visit(urls.globalAuthMethods); | ||
await a11yAudit(); | ||
|
||
currentSession().set('data.theme', 'dark'); | ||
await a11yAudit(); | ||
}); | ||
}); | ||
|
||
test('users can navigate to auth methods with proper authorization', async function (assert) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None blocking comment: the group of tests which do not belong to the a11Audit aren't group by a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing this out as looking at this is confusing. All the tests in this file are wrapped in a module named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh gotcha. Now I see it, Yeah, not a strong opinion which can be the best formula for that. I am fine with it 😉 and you are leading this initiative, so whatever you think is best, let's keep with it and we can review later if its a problem. Great work!! |
||
|
@@ -116,6 +180,22 @@ module('Acceptance | auth-methods | list', function (hooks) { | |
assert.dom(`[href="${urls.authMethods}"]`).exists(); | ||
}); | ||
|
||
test('visiting auth methods in org scope', async function (assert) { | ||
await visit(urls.orgScope); | ||
|
||
await click(`[href="${urls.orgAuthMethods}"]`); | ||
|
||
assert.strictEqual(currentURL(), urls.orgAuthMethods); | ||
}); | ||
|
||
test('visiting auth methods in global scope', async function (assert) { | ||
await visit(urls.globalScope); | ||
|
||
await click(`[href="${urls.globalAuthMethods}"]`); | ||
|
||
assert.strictEqual(currentURL(), urls.globalAuthMethods); | ||
}); | ||
|
||
test('user can search for a specifc auth-method by id', async function (assert) { | ||
await visit(urls.orgScope); | ||
|
||
|
@@ -139,7 +219,7 @@ module('Acceptance | auth-methods | list', function (hooks) { | |
assert.dom(`[href="${urls.passwordAuthMethod}"]`).exists(); | ||
assert.dom(`[href="${urls.oidcAuthMethod}"]`).exists(); | ||
|
||
await fillIn(SEARCH_INPUT_SELECTOR, 'fake target that does not exist'); | ||
await fillIn(SEARCH_INPUT_SELECTOR, 'fake auth method that does not exist'); | ||
await waitFor(NO_RESULTS_MSG_SELECTOR, { count: 1 }); | ||
|
||
assert.dom(`[href="${urls.passwordAuthMethod}"]`).doesNotExist(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big fan of using
test.each
for this, I didn't realize this actually existed and wanted to parametrize some tests before and would've loved to have done this instead!