aws / aws/graph-explorer

Spike: extract a shared component-render test helper to reduce test harness duplication

Open
#1,917 0 comments 0 reactions 1 assignee Claimed by @kmcginnes View on GitHub
internal tech debt
Dominant language
TypeScript
Stars
481
Forks
108
Avg merge
8d 9h
Merged PRs (30d)
7

Description

## Description

Multiple component test files duplicate the same render-wrapper pattern: create a `QueryClient`, wrap the component in `QueryClientProvider` + jotai `Provider` + `TooltipProvider`, seed state via `DbState.applyTo(store)`. This pattern appears at least in `SchemaExplorerSidebar.test.tsx`, `Styles.test.tsx`, and others with similar shape.

The seam is: a render function that wraps any component in the standard required context providers, given a `DbState` to seed. Today every test file re-derives this boilerplate.

## Questions to investigate

- What is the right abstraction boundary? A `renderWithState(component, state)` that returns the standard `render()` result? Or a reusable wrapper-component factory?
- Should it compose with the existing `renderHookWithState` (which already handles the Jotai store + QueryClient for hook tests)? Is there a unified `TestProvider` that both can share?
- Does the `vi.mock("react-virtuoso", ...)` block (also duplicated across files that render Virtuoso lists) belong in a shared mock utility, or should it stay per-file since mocking has test-file scope?
- What about the `getAppStore()` call — should the helper own creating a fresh store, or should callers still pass one?

## Desired outcome

A concrete recommendation (with a sketch) for a `@/utils/testing` helper that reduces component-test boilerplate without coupling tests to each other. The helper should be opt-in (existing tests don't break if they don't adopt it) and composable with `DbState`.

## Related

- Observed in #1914 (Combine styling sidebars) — `renderStyles` and `renderSidebar` are near-identical.
- `renderHookWithState` already solves the hook-level version of this pattern.

> [!IMPORTANT]
> Internal only — this issue is maintained by the core team and is not accepting external contributions.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.