Skip to content

[quality] Missing unit tests for web/src/lib/cards/CardLayout.tsx primitives #22377

Description

@kubestellar-hive

Finding

web/src/lib/cards/CardLayout.tsx exports 8 layout primitives used broadly across card components:

  • CardBody, CardBodyLoaded, CardBodyEmpty
  • CardScrollList
  • CardHeaderRow, CardHeaderActions
  • CardStatGrid, CardStatHeader

These primitives own the canonical Tailwind class strings that guarantee consistent card layout (min-h-card, content-loaded, flex flex-col, grid grid-cols-2 mb-4, etc.). They are consumed by ArgoCDApplications.tsx, ArgoCDApplicationSets.tsx, CRDHealth.tsx, ClusterComparison.tsx and many more (recent PR #22357 adds even more CardStatGrid consumers).

Despite their central role, there is no CardLayout.test.tsx in web/src/lib/cards/. Every consumer test mocks these primitives out with plain <div>s, so:

  1. A silent regression to the class strings (e.g. dropping min-h-card or flipping content-loaded) would not fail any test.
  2. Consumers that add a new primitive (CardStatGrid in [scanner] refactor: centralize repeated code patterns #22352 #22357) already have to keep repeating mock stubs — a single canonical test on the primitive itself prevents drift between mocks and reality.
  3. The className merge semantics (via cn(...)) — where callers append responsive breakpoints like @md:grid-cols-3 — is entirely uncovered.

Recommendation

Add web/src/lib/cards/CardLayout.test.tsx with lightweight @testing-library/react render tests that assert, for each exported primitive:

  1. It renders as a <div> and forwards children.
  2. The canonical base classes are present (e.g. CardBody contains min-h-card, flex, flex-col; CardStatGrid contains grid grid-cols-2 mb-4; CardBodyEmpty contains items-center justify-center text-muted-foreground).
  3. A caller-supplied className is merged onto (not replacing) the base classes.
  4. Additional DivProps (e.g. data-testid, role, onClick) are forwarded to the root <div>.

This is a small, self-contained test file (~120 LOC) and lands purely in web/. It runs under the existing vitest web test job — no CI wiring changes required.

Priority

  • Impact: medium (guards the layout contract for 20+ consumer cards; catches silent Tailwind-class regressions)
  • Effort: low (single test file, no fixtures, no async)

Filed by quality agent (ACMM L4/L6 — full mode)

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.qualitytesting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions