Skip to content

Commit

Permalink
UI: Test reorganization (#26340)
Browse files Browse the repository at this point in the history
  • Loading branch information
hashishaw authored Apr 10, 2024
1 parent 71758f4 commit 82eda87
Show file tree
Hide file tree
Showing 181 changed files with 3,078 additions and 3,219 deletions.
2 changes: 1 addition & 1 deletion ui/app/helpers/supported-auth-backends.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const ENTERPRISE_AUTH_METHODS = [
];

export function supportedAuthBackends() {
return SUPPORTED_AUTH_BACKENDS;
return [...SUPPORTED_AUTH_BACKENDS];
}

export function allSupportedAuthBackends() {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/serializers/clients/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { formatISO } from 'date-fns';
import { formatByMonths, formatByNamespace, destructureClientCounts } from 'core/utils/client-count-utils';
import timestamp from 'core/utils/timestamp';

// see tests/helpers/clients for sample API response (ACTIVITY_RESPONSE_STUB)
// see tests/helpers/clients/client-count-helpers for sample API response (ACTIVITY_RESPONSE_STUB)
// and transformed by_namespace and by_month examples (SERIALIZED_ACTIVITY_RESPONSE)
export default class ActivitySerializer extends ApplicationSerializer {
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
Expand Down
35 changes: 35 additions & 0 deletions ui/docs/tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Test Helpers Organization

Our test are constantly evolving, but here's a general overview of how we set up and organize tests.

## Folder organization

### /acceptance

Acceptance tests should test the overall workflows and navigation within Vault. When possible, they should use the real API instead of mocked so that breaking changes from the backend can be caught. Reasons you may opt to use a mocked backend instead of the real one:

- Using the real backend would cause instability in concurrently-running tests (eg. seal/unseal flow)
- There isn't a way to set up a 3rd party dependency that the backend needs to run correctly (Database Secrets Engine, Sync Secrets)

### /helpers

Shared helpers such as selectors, common interactions, WebREPL commands, and API response stubs live in this folder. When selectors are only used for a single test, they should be defined on the same file where they are used for the test. Once the selectors are being used for multiple tests, they should be moved to this folder so they can be defined in a single place and shared to wherever they are needed.

Often we will need a set of selectors for "workflow" tests, or acceptance tests that navigate through an area of the app. For these, the helpers should be organized as such:

- `/helpers/<area>/<area>-selectors.ts` - exports selector consts (never default) for each page -- eg. for PKI we would have PKI_OVERVIEW, PKI_ROLE, etc.
- `/helpers/<area>/<area>-helpers.js` - exports methods and consts which are otherwise helpful in the tests -- eg. example API responses, common interactions (eg. writeVersionedSecret for KV v2)

Whenever possible we should try to use the general selectors exported from `/helpers/general-selectors.ts`.

### integration

Integration tests are most often used to test specific components out of context from the rest of the app. Be sure to mock anything that the component needs to work correctly -- for example, if the component has a certain behavior in enterprise than community edition, in your tests for each scenario it should not assume that the underlying Vault binary is in one state or the other, and mock the enterprise/community state in all the scenarios. The exports in `helpers/stubs.js` might be helpful for these tests, particularly when the component uses a model which fetches capabilities.

### pages

[DEPRECATED] This file should be removed in favor of selectors within the "helpers" folder. We are moving away from ember-page-object selectors toward simple strings

### unit

Unit tests are most often used to test utils, adapters, serializers, routes, and services functionality.
12 changes: 4 additions & 8 deletions ui/lib/pki/addon/components/page/pki-configure-create.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-engine-page-title>
<h1 class="title is-3" data-test-page-title>
{{this.title}}
</h1>
</p.levelLeft>
Expand Down Expand Up @@ -85,14 +85,10 @@
@onComplete={{transition-to "vault.cluster.secrets.backend.pki.overview"}}
/>
{{else}}
<EmptyState
@title="Choose an option"
@message="To see configuration options, choose your desired output above."
data-test-configuration-empty-state
/>
<EmptyState @title="Choose an option" @message="To see configuration options, choose your desired output above." />
<hr class="has-background-gray-100" />
<Hds::ButtonSet>
<Hds::Button @text="Done" disabled={{true}} data-test-pki-config-save />
<Hds::Button @text="Cancel" @color="secondary" {{on "click" @onCancel}} data-test-pki-config-cancel />
<Hds::Button @text="Done" disabled={{true}} data-test-save />
<Hds::Button @text="Cancel" @color="secondary" {{on "click" @onCancel}} data-test-cancel />
</Hds::ButtonSet>
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-page-title>
<h1 class="title is-3" data-test-page-title>
{{this.title}}
</h1>
</p.levelLeft>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-page-title>
<h1 class="title is-3" data-test-page-title>
{{this.title}}
</h1>
</p.levelLeft>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/components/page/pki-issuer-import.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-page-title>
<h1 class="title is-3" data-test-page-title>
{{this.title}}
</h1>
</p.levelLeft>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/components/page/pki-issuer-list.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
@text="Details"
@route="issuers.issuer.details"
@model={{pkiIssuer.id}}
data-test-popup-menu-details
data-test-pki-issuer-details
/>
<dd.Interactive @text="Edit" @route="issuers.issuer.edit" @model={{pkiIssuer.id}} />
</Hds::Dropdown>
Expand Down
6 changes: 3 additions & 3 deletions ui/lib/pki/addon/components/page/pki-issuer-rotate-root.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{@breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-page-title>
<h1 class="title is-3" data-test-page-title>
{{if @newRootModel.id "View Issuer Certificate" "Generate New Root"}}
</h1>
</p.levelLeft>
Expand Down Expand Up @@ -166,8 +166,8 @@

<hr class="has-background-gray-100" />
<Hds::ButtonSet>
<Hds::Button @text="Done" type="submit" data-test-pki-rotate-root-save />
<Hds::Button @text="Cancel" @color="secondary" {{on "click" @onCancel}} data-test-pki-rotate-root-cancel />
<Hds::Button @text="Done" type="submit" data-test-save />
<Hds::Button @text="Cancel" @color="secondary" {{on "click" @onCancel}} data-test-cancel />
</Hds::ButtonSet>
{{#if this.invalidFormAlert}}
<div class="control">
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/pki/addon/components/pki-generate-root.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@

<hr class="has-background-gray-100" />
<Hds::ButtonSet>
<Hds::Button @text="Done" type="submit" data-test-pki-generate-root-save />
<Hds::Button @text="Cancel" @color="secondary" {{on "click" @onCancel}} data-test-pki-generate-root-cancel />
<Hds::Button @text="Done" type="submit" data-test-save />
<Hds::Button @text="Cancel" @color="secondary" {{on "click" @onCancel}} data-test-cancel />
</Hds::ButtonSet>
{{#if this.invalidFormAlert}}
<div class="control">
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/pki/addon/components/pki-issuer-cross-sign.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@
@icon={{if this.submit.isRunning "loading"}}
type="submit"
disabled={{this.submit.isRunning}}
data-test-cross-sign-submit
data-test-save
/>
<Hds::Button
@text="Cancel"
@color="secondary"
@route="issuers.issuer.details"
disabled={{this.submit.isRunning}}
data-test-cross-sign-cancel
data-test-cancel
/>
</Hds::ButtonSet>
</form>
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/pki/addon/components/pki-key-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
@icon={{if this.save.isRunning "loading"}}
type="submit"
disabled={{this.save.isRunning}}
data-test-pki-key-save
data-test-save
/>
<Hds::Button
@text="Cancel"
@color="secondary"
disabled={{this.save.isRunning}}
{{on "click" @onCancel}}
data-test-pki-key-cancel
data-test-cancel
/>
</Hds::ButtonSet>
{{#if this.invalidFormAlert}}
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/components/pki-key-import.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@color="secondary"
disabled={{this.submitForm.isRunning}}
{{on "click" this.cancel}}
data-test-pki-key-cancel
data-test-cancel
/>
</Hds::ButtonSet>
{{#if this.invalidFormAlert}}
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/pki/addon/components/pki-role-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@
@icon={{if this.save.isRunning "loading"}}
type="submit"
disabled={{this.save.isRunning}}
data-test-pki-role-save
data-test-save
/>
<Hds::Button
@text="Cancel"
@color="secondary"
disabled={{this.save.isRunning}}
{{on "click" @onCancel}}
data-test-pki-role-cancel
data-test-cancel
/>
</Hds::ButtonSet>
{{#if this.modelValidations.targets.errors}}
Expand Down
4 changes: 2 additions & 2 deletions ui/lib/pki/addon/components/pki-role-generate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
@icon={{if this.save.isRunning "loading"}}
type="submit"
disabled={{this.save.isRunning}}
data-test-pki-generate-button
data-test-save
/>
<Hds::Button
@text="Cancel"
@color="secondary"
disabled={{this.save.isRunning}}
{{on "click" this.cancel}}
data-test-pki-generate-cancel
data-test-cancel
/>
</Hds::ButtonSet>

Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/issuers/issuer/cross-sign.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-issuer-page-title>
<h1 class="title is-3" data-test-page-title>
Cross-Sign Issuers
</h1>
</p.levelLeft>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/issuers/issuer/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-issuer-page-title>
<h1 class="title is-3" data-test-page-title>
<Icon @name="file-text" @size="24" class="has-text-grey-light" />
View Issuer Certificate
</h1>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/issuers/issuer/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-issuer-page-title>
<h1 class="title is-3" data-test-page-title>
Update Issuer
</h1>
</p.levelLeft>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/issuers/issuer/sign.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-issuer-page-title>
<h1 class="title is-3" data-test-page-title>
<Icon @name="file-text" @size="24" class="has-text-grey-light" />
Sign Intermediate
</h1>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/keys/key/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-key-details-title>
<h1 class="title is-3" data-test-page-title>
<Icon @name="certificate" @size="24" class="has-text-grey-light" />
View Key
</h1>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/keys/key/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-key-details-title>
<h1 class="title is-3" data-test-page-title>
<Icon @name="certificate" @size="24" class="has-text-grey-light" />
Edit Key
</h1>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/roles/create.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-role-page-title>
<h1 class="title is-3" data-test-page-title>
Create a PKI Role
</h1>
</p.levelLeft>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/roles/role/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-role-page-title>
<h1 class="title is-3" data-test-page-title>
<Icon @name="file-text" @size="24" class="has-text-grey-light" />
PKI Role
<code>{{this.model.name}}</code>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/roles/role/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-role-page-title>
<h1 class="title is-3" data-test-page-title>
Edit Role
</h1>
</p.levelLeft>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/roles/role/generate.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-role-page-title>
<h1 class="title is-3" data-test-page-title>
<Icon @name="certificate" @size="24" class="has-text-grey-light" />
{{if this.hasSubmitted "View Generated Certificate" "Generate Certificate"}}
</h1>
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/pki/addon/templates/roles/role/sign.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Page::Breadcrumbs @breadcrumbs={{this.breadcrumbs}} />
</p.top>
<p.levelLeft>
<h1 class="title is-3" data-test-pki-role-page-title>
<h1 class="title is-3" data-test-page-title>
<Icon @name="certificate" @size="24" class="has-text-grey-light" />
{{if this.hasSubmitted "View Signed Certificate" "Sign Certificate"}}
</h1>
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/access/identity/entities/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { setupApplicationTest } from 'ember-qunit';
import page from 'vault/tests/pages/access/identity/index';
import authPage from 'vault/tests/pages/auth';
import { runCmd } from 'vault/tests/helpers/commands';
import { SELECTORS as GENERAL } from 'vault/tests/helpers/general-selectors';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
import { v4 as uuidv4 } from 'uuid';

const SELECTORS = {
Expand Down
Loading

0 comments on commit 82eda87

Please sign in to comment.