-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Test reorg: Clients, Mirage, General selectors #26260
Conversation
this.assertReq(req); | ||
req.passthrough(); | ||
}); | ||
this.expected = { |
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.
This is a longer but more explicit way of checking that the url and data are doing what we expect on login
8e1063a
to
bef947d
Compare
CI Results: |
0b8de2d
to
3c4e0e4
Compare
Build Results: |
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.
there are so many great changes in here! i think pulling the mirage helpers into tests/helpers/stubs
really makes a difference. thank you so much for tackling this huge cleanup. 😀
the only changes i think are actually necessary for merging are the comments i prefixed with "🔄 " (mostly easy typo fixes, using assert.true
, etc).
aside from that, i had some optional questions about whether we can swap out assert.ok
for something more strict. i noticed that we're often using assert.ok
inside a stubbed function to verify it was called, which is pretty harmless, but some alternatives to that might be:
// using sinon
const methodStub = sinon.stub();
this.server[method](url, (schema, req) => {
methodStub();
assert.strictEqual(req.method, testCase.method, `uses the correct http verb: ${testCase.method}`);
assert.deepEqual(req.queryParams, queryParams, 'calls with correct query params');
return {};
});
assert.true(methodStub.calledOnce, `${testCase.adapterMethod} calls the correct url with: ${testCase.url}`);
or
// using a variable flag
const methodCalled = false;
this.server[method](url, (schema, req) => {
functionCalled = true; // set the flag to true when the function is called
assert.strictEqual(req.method, testCase.method, `uses the correct http verb: ${testCase.method}`);
assert.deepEqual(req.queryParams, queryParams, 'calls with correct query params');
return {};
});
assert.true(methodCalled, `${testCase.adapterMethod} calls the correct url with: ${testCase.url}`); // Assert that the function was called
});
});
or if we want to make minimal changes
this.server[method](url, (schema, req) => {
assert.true(true, 'calls the correct url'); // this will never fail, but that's okay since we're just testing that this line was executed
assert.strictEqual(req.method, testCase.method, `uses the correct http verb: ${testCase.method}`);
assert.deepEqual(req.queryParams, queryParams, 'calls with correct query params');
return {};
});
^ i'm just sharing these ideas for brainstorming purposes right now, so take it or leave it. but i think we should consider setting up linting rules at some point to disallow or warn when using assert.ok
. what do you think? we can talk about this at the next team pattern discussion too. 🙂
ui/tests/_README.md
Outdated
@@ -0,0 +1,27 @@ | |||
# Test Helpers Organization |
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.
this is a great start to testing docs! thanks so much for writing these. ✨
ui/tests/_README.md
Outdated
|
||
## Process | ||
|
||
- Rename export from `general-selectors` to `GENERAL` |
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.
is this line a todo item? i'm not sure what it's doing 🤔
methods() | ||
.map((backend) => backend.type) | ||
.forEach((type) => { | ||
test(`${type} auth method`, async function (assert) { |
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.
nice improvement adding the loop here!
const url = testCase.url.replace('/v1', '').split('?')[0]; | ||
const queryParams = testCase.url.includes('?list=true') ? { list: 'true' } : {}; | ||
this.server[method](url, (schema, req) => { | ||
assert.ok(true, `${testCase.adapterMethod} calls the correct url with: ${testCase.url}`); |
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.
same question here -- wondering if we can find a way to use assert.strictEqual
or assert.true
🤔
const url = testCase.url.replace('/v1', '').split('?')[0]; | ||
const queryParams = testCase.url.includes('?list=true') ? { list: 'true' } : {}; | ||
this.server[method](url, (schema, req) => { | ||
assert.ok(true, `${testCase.adapterMethod} calls the correct url with: ${testCase.url}`); |
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.
this one too
Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com>
Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com>
Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com>
Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com>
Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com>
Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com>
* Add readme * Rename general selectors export * reorg clients helper -- all clients tests pass * Update custom messages & dashboard selectors * Rename client count selector export * clean up .CodeMirror selectors to use helper instead * move secret-edit-toolbar helper * remove helper used only once * replace noop-all-api-requests with mirage * move policy generators into their respective folders * Move LDAP helpers * Move overrideResponse to stubs helper, rename clients helper * replace oidc-specific mirage & capabilities overrides * add secretTab and checkboxByAttr to general selectors * general-selectors are TS * fix merge conflict import * Bump message wait time for oidc auth method test * Refactor auth methods mgmt test so we don't run into a timeout * Update comment * revert acceptance tests only * don't allow mutability of array returned by supportedAuthBackends * unrevert -- remove noop-all-api-requests * remove hardcoded ?with param * Update ui/tests/_README.md Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com> * Update ui/tests/acceptance/auth-list-test.js Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com> * Update ui/tests/acceptance/auth-test.js Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com> * Update ui/tests/acceptance/settings/auth/configure/section-test.js Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com> * Update ui/tests/unit/adapters/identity/entity-test.js Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com> * Update ui/tests/unit/adapters/identity/entity-alias-test.js Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com> * replace CLIENT_COUNT as ts in tests * update assertions * move readme to docs --------- Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com>
SELECTORS
export to something specificoverrideMirageResponse
and capabilities stubsnoop-all-api-requests
and rewrite those tests to use mirage