Skip to content

test: add useMemoryMatch hook coverage - #1726

Open
SujalMahapatra wants to merge 1 commit into
Canopus-Labs:mainfrom
SujalMahapatra:test/use-memory-match
Open

test: add useMemoryMatch hook coverage#1726
SujalMahapatra wants to merge 1 commit into
Canopus-Labs:mainfrom
SujalMahapatra:test/use-memory-match

Conversation

@SujalMahapatra

@SujalMahapatra SujalMahapatra commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

📝 Pull Request Description

Related Issue

Closes #1721

Summary

Provide a short, reviewer-friendly summary of what changed and why.

Added comprehensive Vitest coverage for the useMemoryMatch React hook.

The test suite covers the hook's core game lifecycle, including initialization, persisted high scores, difficulty configuration, game startup, card generation, timers, pause/resume behavior, quitting, accuracy calculation, and difficulty changes.

Also added the required React Testing Library dependency to properly test the hook with renderHook and act.


Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature
  • ♻️ Refactoring
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • 🔥 Other(please describe) ______

How Has This Been Tested?

Describe the testing steps performed.

  • Added useMemoryMatch.test.js with 10 automated tests.
  • Verified the default hook state and persisted high-score behavior.
  • Verified all difficulty configurations.
  • Tested game initialization and card-pair generation.
  • Tested elapsed-time updates using Vitest fake timers.
  • Tested pause and resume functionality.
  • Tested quitting and returning to the instructions phase.
  • Tested accuracy calculation.
  • Tested changing difficulty before starting a game.
  • Ran the dedicated test suite:
10 tests passed

Screenshots (if applicable)

Add screenshots or videos to demonstrate the changes.


Checklist

  • My code follows the project's guidelines
  • I have tested my changes
  • I have updated documentation where necessary
  • I have linked the related issue
  • My changes do not introduce new warnings or errors

Adds comprehensive Vitest coverage for useMemoryMatch.

  • Adds 10 automated tests for initialization, persisted high scores, difficulty settings, game setup, card matching, timers, pause/resume, quitting, accuracy, and difficulty changes.
  • Mocks audio and daily-seed dependencies.
  • Resets storage, mocks, and timers between tests.
  • Adds @testing-library/react for renderHook and act.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Added a dedicated Vitest suite for useMemoryMatch. The tests cover initial state, high scores, difficulty settings, deck setup, timers, pause/resume, quitting, accuracy, and pre-game changes.

Changes

Memory Match hook coverage

Layer / File(s) Summary
Test harness and initial state
frontend/package.json, frontend/src/hooks/useMemoryMatch.test.js
Added React Testing Library and configured mocked dependencies, cleanup, initial state checks, high-score loading, and difficulty configuration tests.
Game initialization and controls
frontend/src/hooks/useMemoryMatch.test.js
Tested difficulty selection, paired deck initialization, quitting, default accuracy, and pre-game difficulty changes.
Timer and pause behavior
frontend/src/hooks/useMemoryMatch.test.js
Added fake-timer tests for elapsed time and pause/resume behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The test suite covers many requested behaviors, but the summary does not confirm matching outcomes, score updates, victory, or reset-after-completion tests. Confirm that tests cover matching and non-matching pairs, score and bonus scoring, victory, final and high scores, and reset after completion.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding test coverage for the useMemoryMatch hook.
Out of Scope Changes check ✅ Passed The changes add the requested hook tests and the React Testing Library dependency needed to support them.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/hooks/useMemoryMatch.test.js`:
- Around line 1-8: Remove act from the React import and retain the act import
from `@testing-library/react`, leaving the existing renderHook import unchanged.
- Around line 126-134: Update the card-count assertion in the useMemoryMatch
test to compare Object.values(counts) exactly with Array(8).fill(2), replacing
the permissive expect.arrayContaining matcher while retaining the eight-key
assertion.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b02b67f-72ce-4c3e-9f4d-f81e2e070073

📥 Commits

Reviewing files that changed from the base of the PR and between 90c2e5b and 6574205.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • frontend/package.json
  • frontend/src/hooks/useMemoryMatch.test.js

Comment thread frontend/src/hooks/useMemoryMatch.test.js
Comment thread frontend/src/hooks/useMemoryMatch.test.js
@SujalMahapatra

Copy link
Copy Markdown
Contributor Author

Hi @KaranUnique ,
Please merge this pr under gssoc'26

@github-actions github-actions Bot added the merge ready PR is mergeable and has no conflicts label Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready PR is mergeable and has no conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: [TEST]: Add Vitest coverage for useMemoryMatch hook

1 participant