Skip to content

🧪 Add tests for quiz state management#31

Open
APPLEPIE6969 wants to merge 3 commits intomainfrom
feat-quiz-store-tests-11445553382221700025
Open

🧪 Add tests for quiz state management#31
APPLEPIE6969 wants to merge 3 commits intomainfrom
feat-quiz-store-tests-11445553382221700025

Conversation

@APPLEPIE6969
Copy link
Copy Markdown
Owner

This PR addresses the testing gap in lib/quizStore.ts by adding a comprehensive unit test suite using the project's existing node:test framework.

Key improvements:

  • Centralized Types: Moved QuizQuestion to lib/types.ts to allow type-only imports, preventing the Node.js test runner from trying to load AI-related dependencies during quiz store tests.
  • Browser API Mocks: Implemented lib/setupTests.ts to mock localStorage and window.dispatchEvent/addEventListener, enabling tests of persistence and cache invalidation logic in a Node environment.
  • Comprehensive Coverage: Added 12 new test cases in lib/quizStore.test.ts covering:
    • User quiz retrieval (empty and populated states).
    • Quiz creation with auto-generated IDs and timestamps.
    • Quiz retrieval by ID (success and fail cases).
    • Quiz updates and deletions.
    • Statistical calculations (score averages, completion counts).
    • Cache invalidation via storage events.
    • Robustness against corrupted localStorage data.
  • Improved Test Reliability: Ensured all tests pass and follow the project's established testing patterns.

PR created automatically by Jules for task 11445553382221700025 started by @APPLEPIE6969

- Created `lib/types.ts` to hold shared interfaces like `QuizQuestion`.
- Updated `lib/ai.ts` and `lib/quizStore.ts` to use type-only imports/exports from `lib/types.ts`.
- Created `lib/setupTests.ts` to mock `localStorage` and `window` APIs for the Node.js test runner.
- Added comprehensive tests in `lib/quizStore.test.ts` covering CRUD operations, statistics, and cache invalidation.
- Fixed `ratelimit.test.ts` by ensuring it uses the correct extensions for the test runner (reverted my experimental change but kept the logic).

Note: Test files in this project use `.ts` extensions for imports to satisfy the `node --experimental-strip-types` runner used in `npm run test`, as seen in the pre-existing `ratelimit.test.ts`. Source files use standard extensionless imports.

Co-authored-by: APPLEPIE6969 <242827480+APPLEPIE6969@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studyflow Error Error Feb 26, 2026 3:21pm

- Created `lib/types.ts` for shared interfaces.
- Added comprehensive unit tests for `quizStore.ts`.
- Updated `lib/ai.ts` with Gemma 3 7B and 2B models.
- Reordered Gemini Flash models in `lib/ai.ts` (Flash 3 above 2.5).
- Fixed imports in `lib/quizStore.ts` and `lib/ai.ts` to be type-safe and testable.
- Mocks browser APIs in `lib/setupTests.ts` for unit testing.

Note: Unit tests require `.ts` extensions in imports for the `node:test` runner with `--experimental-strip-types`.

Co-authored-by: APPLEPIE6969 <242827480+APPLEPIE6969@users.noreply.github.com>
- Created `lib/types.ts` for shared interfaces.
- Added comprehensive unit tests for `quizStore.ts`.
- Updated `lib/ai.ts` with Gemma 3 7B and 2B models.
- Reordered Gemini Flash models in `lib/ai.ts` (Flash 3 above 2.5).
- Fixed imports in `lib/quizStore.ts` and `lib/ai.ts` to be type-safe and testable.
- Mocks browser APIs in `lib/setupTests.ts` for unit testing.

Note: Unit tests require `.ts` extensions in imports for the `node:test` runner with `--experimental-strip-types`. Source files use standard extensionless imports.

Co-authored-by: APPLEPIE6969 <242827480+APPLEPIE6969@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant