Skip to content

Add tests for the theme helper and ThemeToggle component #16

@mikewheeleer

Description

@mikewheeleer

Test the theme helpers and ThemeToggle behaviour

Description

src/lib/theme.ts (read/write/effective theme with matchMedia) and src/components/ThemeToggle.tsx (which toggles the dark class on documentElement) have no tests. Regressions here silently break dark mode across every page. This issue adds coverage for both.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-frontend only.
  • For theme.ts: assert readTheme validates the stored value, writeTheme persists, and effectiveTheme("system") follows a mocked matchMedia.
  • For ThemeToggle: mock localStorage and matchMedia, assert the three buttons render, aria-pressed reflects the active theme, and clicking toggles documentElement.classList.
  • Stub window.matchMedia in the test setup since jsdom lacks it.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b test/testing-17-theme
  • Implement changes
    • Write comprehensive tests in: create src/lib/__tests__/theme.test.ts and src/components/__tests__/ThemeToggle.test.tsx.
    • Add documentation: if you add a matchMedia polyfill, note it in jest.setup.ts.
    • Validate the role="group" with aria-label="Theme" is reachable.
  • Test and commit

Test and commit

  • Run npm run lint, npm run typecheck, and npm test.
  • Cover edge cases: invalid stored value coerced to system, SSR guards (typeof window === "undefined"), and dark-preference media query.
  • Include the npm test output and coverage for the two modules.

Example commit message

test(theme): cover theme helpers and ThemeToggle dark-mode wiring

Guidelines

  • Minimum 95 percent test coverage for the impacted modules.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions