Skip to content

Add tests for the colorblind simulation matrices (no test file) #886

Description

@TortoiseWolfe

The task

src/utils/colorblind-matrices.ts exports the colour-blindness simulation matrices and the
helpers that turn them into SVG filter strings. It has no test file. Add one.

Why this is a good first issue

COLORBLIND_MATRICES is data, and matrixToSVGString, getColorblindMatrixString and
isValidColorMatrix are pure functions over it. No DOM, no network. It also backs a real
accessibility feature, so the tests are worth having rather than busywork.

Where the test goes

src/utils/colorblind-matrices.test.ts, beside the source.

Acceptance criteria

  • A test file exists at src/utils/colorblind-matrices.test.ts
  • Every entry in COLORBLIND_MATRICES is validated — iterate the object rather than
    hardcoding a list of types, so a matrix added later is covered automatically
  • isValidColorMatrix is tested in both directions: a real matrix passes, and a
    malformed one (wrong length, a non-number) fails. A validator only ever seen saying "yes"
    has not been shown to work
  • matrixToSVGString produces the expected shape for a known matrix
  • getColorblindMatrixString returns something sensible for each supported type
  • docker compose exec scripthammer pnpm test --run src/utils/colorblind-matrices.test.ts passes

Skip this one

measureFilterPerformance uses performance.now() and is about timing rather than logic. Leave
it out — timing assertions are flaky and this repo has actively removed them (#300).

The one thing that matters here

The isValidColorMatrix both-directions requirement is the whole point. Then break something on
purpose — corrupt one matrix in the data, or make the validator always return true — and
confirm your test goes red. Say which mutation you tried in the PR. A gate that cannot fail is
the most common defect in this repo (#396).

Getting set up

docker compose up -d
docker compose exec scripthammer pnpm test --run src/utils/colorblind-matrices.test.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions