Skip to content
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

Merged
merged 33 commits into from
Apr 10, 2024

Conversation

hashishaw
Copy link
Contributor

@hashishaw hashishaw commented Apr 3, 2024

  • Rename SELECTORS export to something specific
  • Consolidate helpers such as overrideMirageResponse and capabilities stubs
  • Remove noop-all-api-requests and rewrite those tests to use mirage

@hashishaw hashishaw added the ui label Apr 3, 2024
this.assertReq(req);
req.passthrough();
});
this.expected = {
Copy link
Contributor Author

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

@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Apr 4, 2024
Copy link

github-actions bot commented Apr 4, 2024

CI Results:
All Go tests succeeded! ✅

@hashishaw hashishaw changed the base branch from main to ui/test-reorg-base April 5, 2024 13:56
@hashishaw hashishaw changed the title UI: Test reorganization Test reorg: Clients, Mirage, General selectors Apr 5, 2024
@hashishaw hashishaw marked this pull request as ready for review April 5, 2024 13:59
Copy link

github-actions bot commented Apr 5, 2024

Build Results:
All builds succeeded! ✅

Copy link
Contributor

@andaley andaley left a 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. 🙂

@@ -0,0 +1,27 @@
# Test Helpers Organization
Copy link
Contributor

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 Show resolved Hide resolved

## Process

- Rename export from `general-selectors` to `GENERAL`
Copy link
Contributor

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) {
Copy link
Contributor

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!

ui/tests/acceptance/auth-list-test.js Outdated Show resolved Hide resolved
ui/tests/integration/components/clients/page/token-test.js Outdated Show resolved Hide resolved
ui/tests/unit/adapters/identity/entity-test.js Outdated Show resolved Hide resolved
ui/tests/unit/adapters/identity/entity-alias-test.js Outdated Show resolved Hide resolved
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}`);
Copy link
Contributor

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}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one too

hashishaw and others added 9 commits April 10, 2024 08:55
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>
@hashishaw hashishaw merged commit b793b7f into ui/test-reorg-base Apr 10, 2024
23 checks passed
@hashishaw hashishaw deleted the ui/hackweek-test-reorg branch April 10, 2024 14:37
hashishaw added a commit that referenced this pull request Apr 10, 2024
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed pr/no-changelog pr/no-milestone ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants