Skip to content

test(ui): extract shared test helpers to reduce boilerplate - #6928

Merged
otavio merged 4 commits into
masterfrom
test/ui/shared-test-helpers
Aug 19, 2026
Merged

test(ui): extract shared test helpers to reduce boilerplate#6928
otavio merged 4 commits into
masterfrom
test/ui/shared-test-helpers

Conversation

@luizhf42

Copy link
Copy Markdown
Member

What

Shared test utilities in src/tests/ replace duplicated boilerplate scattered across ~50 console test files, cutting ~500 net lines.

Why

The console test suite had identical helper definitions copied across dozens of files — createWrapper/createQueryWrapper (30 copies with config drift), mockSdkResponse (15 copies), makeSdkError (5 copies), LocationProbe (3 copies), and mockUserAuth (3 copies). Each copy was slightly different (4 distinct QueryClient configs, varying error shapes), making it hard to know which was correct and easy to introduce subtle test bugs.

Partial work toward shellhub-io/team#216

Changes

  • src/tests/wrapper.tsx: createTestWrapper() — composable wrapper factory accepting optional queryClient and initialEntries (for MemoryRouter). renderHookWithClient() — convenience for hook tests. Superset QueryClient config (retry: false, gcTime: 0) eliminates config drift across the 4 variants that existed before.
  • src/tests/sdk.ts: mockSdkResponse<T>() with optional headers parameter (superset of the simple and with-headers variants), makeSdkError() that properly creates an Error with status and headers (some local copies only had { status } without Error or Headers), and the SdkResponse type alias.
  • src/tests/LocationProbe.tsx: callback-style LocationProbe component for URL assertion in routing tests (3 duplicates replaced; the single-use DOM variant in CommandPalette.test.tsx was intentionally left local).
  • src/tests/userAuth.ts: mockUserAuth() factory for UserAuth fixtures (3 duplicates replaced).
  • src/tests/renderHookWithRouter.tsx: refactored to delegate to createTestWrapper instead of duplicating the QueryClient + MemoryRouter setup.

Testing

npm run --workspace apps/console test — all 211 test files pass. The shared helpers themselves have unit tests in src/tests/__tests__/.

Add `createTestWrapper()` and `renderHookWithClient()` to
`src/tests/wrapper.tsx`, replacing 30 ad-hoc `createWrapper` /
`createQueryWrapper` helpers scattered across test files.
`renderHookWithRouter` now delegates to `createTestWrapper` instead of
duplicating the `QueryClient` + `MemoryRouter` setup.
…s/sdk.ts`

Replaces 15 local `mockSdkResponse` definitions, 13 local `SdkResponse`
type aliases, and 5 local `makeSdkError` helpers with shared imports.
@luizhf42
luizhf42 requested a review from a team as a code owner August 19, 2026 20:07
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

Code Review Complete

The automated review ran but did not post an updated summary — this usually means no new issues were found since the previous review. If you've pushed changes and want a fresh pass, comment /review.

View job

@otavio
otavio merged commit 4deb365 into master Aug 19, 2026
40 checks passed
@otavio
otavio deleted the test/ui/shared-test-helpers branch August 19, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants