Skip to content

Conversation

@erentantekin
Copy link
Contributor

@erentantekin erentantekin commented May 14, 2025

Description

[UI] VAULT-36185 Acceptance tests for Reporting

Adds acceptance tests for reporting dashboard.

TODO only if you're a HashiCorp employee

  • Backport Labels: If this fix needs to be backported, use the appropriate backport/ label that matches the desired release branch. Note that in the CE repo, the latest release branch will look like backport/x.x.x, but older release branches will be backport/ent/x.x.x+ent.
    • LTS: If this fixes a critical security vulnerability or severity 1 bug, it will also need to be backported to the current LTS versions of Vault. To ensure this, use all available enterprise labels.
  • ENT Breakage: If this PR either 1) removes a public function OR 2) changes the signature
    of a public function, even if that change is in a CE file, double check that
    applying the patch for this PR to the ENT repo and running tests doesn't
    break any tests. Sometimes ENT only tests rely on public functions in CE
    files.
  • Jira: If this change has an associated Jira, it's referenced either
    in the PR description, commit message, or branch name.
  • RFC: If this change has an associated RFC, please link it in the description.
  • ENT PR: If this change has an associated ENT PR, please link it in the
    description. Also, make sure the changelog is in this PR, not in your ENT PR.

@erentantekin erentantekin requested a review from a team as a code owner May 14, 2025 19:52
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label May 14, 2025
@github-actions
Copy link

github-actions bot commented May 14, 2025

Build Results:
All builds succeeded! ✅

@github-actions
Copy link

github-actions bot commented May 14, 2025

CI Results:
All Go tests succeeded! ✅

test('it renders the counters dashboard block with all expected counters', async function (assert) {
this.server.get('http://localhost:7357/v1/sys/utilization-report', () => mockedResponseWithData);
await visit('/vault/usage-reporting');
await waitFor('[data-test-dashboard-counters]');
Copy link
Contributor

Choose a reason for hiding this comment

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

Up to you guys, but I recommend creating a vault-usage helper directory & file. Similar to something like this.

await waitFor('[data-test-dashboard-secret-engines]');

const card = document.querySelector('[data-test-dashboard-secret-engines]');
assert.ok(card, 'renders Secret engines card');
Copy link
Contributor

Choose a reason for hiding this comment

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

We try not to use assert.ok, but instead assert.true or assert.false

this.server.get('http://localhost:7357/v1/sys/utilization-report', () => mockedResponseWithData);
await visit('/vault/usage-reporting');
await waitFor('[data-test-dashboard-counters]');
assert.dom('[data-test-dashboard-counters]').exists('renders the counters dashboard block');
Copy link
Contributor

Choose a reason for hiding this comment

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

To help avoid confusion with other areas of our app that have the concept of dashboard, could we change these selectors here to something like data-test-usage-counters? If you do a quick search of the app you can see the use of data-test-dashboard-... in several places.

.includesText('Global lease count quota', 'Lease quota empty state: docs link is shown');
});

//
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
//


const mockedResponseWithData = {
data: {
auth_methods: { cats: 42 },
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the keys here auth method types or paths? I'm guessing paths because of the numerical number. For posterity it might be helpful to name these more similar to the real-world.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, they're paths. i updated their names and added more options.

@erentantekin erentantekin requested review from a team as code owners May 23, 2025 14:08
@erentantekin erentantekin removed request for a team, anwittin and brewgator May 23, 2025 14:26
@erentantekin erentantekin enabled auto-merge (squash) May 27, 2025 19:03
});

test('it renders the counters dashboard block with all expected counters', async function (assert) {
this.server.get('http://localhost:7357/v1/sys/utilization-report', () => mockedResponseWithData);
Copy link
Contributor

Choose a reason for hiding this comment

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

typically we remove the origin from the url example when stubbing mirage responses so that if something with the host in CI changes tests won't fail. Removing v1 should also be possible because the server should automatically prefix that

Suggested change
this.server.get('http://localhost:7357/v1/sys/utilization-report', () => mockedResponseWithData);
this.server.get('sys/utilization-report', () => mockedResponseWithData);

Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com>
await login();
});

test('it visits the usage reporting dashboard and renders the header', 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.

Since this test is asserting navigation, I think it would be a little more resilient to click the sidebar nav link rather than visit the route directly. That way we get the added benefit of testing the conditionals wrapping the link (which from what I could tell, currently only have integration tests)

await visit('/vault/usage-reporting');
await waitFor('[data-test-vault-reporting-dashboard-secret-engines]');

assert.dom('[data-test-vault-reporting-dashboard-secret-engines]').exists('renders Secret engines card');
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessary to update, but mostly an FYI. We typically use const SELECTORS var at either the top of the test file, or in a separate helper file if they'll be reused elsewhere, to streamline future test selector updates. Here's an example of a dynamic selector so that the test file just references SELECTORS.card('secret-engines').


test('it visits the usage reporting dashboard and renders the header', async function (assert) {
await visit('/vault/dashboard');
await click('[data-test-sidebar-nav-link="Vault Usage"]');
Copy link
Contributor

Choose a reason for hiding this comment

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

👏 awesome, thanks!

@erentantekin erentantekin merged commit bc430db into main May 27, 2025
33 checks passed
@erentantekin erentantekin deleted the ui/VAULT-36185 branch May 27, 2025 21:23
Erfankam pushed a commit to Erfankam/vault that referenced this pull request Sep 1, 2025
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants