Skip to content

Conversation

@codegen-sh
Copy link
Contributor

@codegen-sh codegen-sh bot commented Aug 9, 2025

Requested by: Jake Ruesink

Summary
Adds missing unit tests for storage utilities and extends todo-context tests to validate hydration and persistence flows for the new localStorage integration.

What

  • packages/utils/src/tests/storage.test.ts (new)
    • Verifies SSR/test guard returns fallback
    • Malformed JSON returns fallback
    • Optional validate guard path (accepts/rejects)
    • save/remove round-trip behavior
  • apps/todo-app/app/lib/tests/todo-context.test.tsx (extended)
    • Hydration revives dates (via provider mount reading from storage and reviving createdAt/updatedAt)
    • Persistence triggers on addTodo, toggleTodo, setFilter (spy on saveToStorage)
    • Guarded against unavailable window/localStorage

Notes

  • Utils tests use a jsdom-safe localStorage polyfill when needed and flip NODE_ENV to exercise the storage path safely.
  • Todo app already has jsdom setup; we isolate persistence behaviors and do not alter other existing component tests.

Compliance with org/repo rules

  • Branch created from base branch
  • Lint/typecheck to be run by CI; focused only on requested test coverage
  • No time estimates included

Links

Requested by: Jake Ruesink


💻 View my work • 👤 Initiated by Jake RuesinkAbout Codegen
⛔ Remove Codegen from PR🚫 Ban action checks

…d todo-context tests for hydration + persistence

Co-authored-by: Jake Ruesink <[email protected]>
@linear
Copy link

linear bot commented Aug 9, 2025

STA-10 [Testing] Add storage + hydration tests (utils + todo-context)

Requested by: Jake Ruesink

Summary
Increase confidence in the new persistence path by adding tests that cover storage guards, validation fallback, hydration date revival, and persistence triggers.

Base branch for PR: codegen-bot/persist-todos-localstorage-STA-2-1754688724
Target repo: lambda-curry/react-router-starter

Code context

  1. Add: packages/utils/src/tests/storage.test.ts
  • Cover:
    • SSR/test guard disables storage
    • Malformed JSON returns fallback
    • Optional validate guard path (accept and reject)
    • save/remove round-trip behavior
  1. Extend: apps/todo-app/app/lib/tests/todo-context.test.tsx
  • Cover:
    • Hydration revives dates (createdAt/updatedAt are Date after mount)
    • Persistence triggers on: addTodo, toggleTodo, setFilter
    • No SSR errors when window/localStorage not available

Testing notes

  • Mock window.localStorage in JSDOM-safe ways.
  • Use spies to assert saves, and manually seed storage JSON for hydration tests.

Acceptance criteria

  • Tests pass locally and in CI.
  • Regressions like invalid JSON in storage or missing SSR guards are caught by tests.

References

@coderabbitai
Copy link

coderabbitai bot commented Aug 9, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codegen/sta-10-testing-add-storage-hydration-tests-utils-todo-context

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jaruesink jaruesink changed the base branch from main to codegen-bot/persist-todos-localstorage-STA-2-1754688724 August 9, 2025 02:50
…' into codegen/sta-10-testing-add-storage-hydration-tests-utils-todo-context
@jaruesink jaruesink marked this pull request as ready for review August 9, 2025 03:20
…' of github.com:lambda-curry/react-router-starter into codegen/sta-10-testing-add-storage-hydration-tests-utils-todo-context
…e handling and cleanup

This update refines the todo-context tests by introducing a consistent localStorage polyfill for Node environments, ensuring reliable test execution. It also improves the cleanup logic in the tests to maintain a clean state between runs. Additionally, minor formatting adjustments are made for better readability.
This update simplifies the todo context reducer by consolidating conditional expressions for better readability. Additionally, it enhances the test suite by allowing real localStorage usage in tests, ensuring more accurate persistence behavior during testing. Minor formatting adjustments are also made for consistency.
This update refines the loadFromStorage function by consolidating its signatures for improved clarity and consistency. The changes enhance type safety while maintaining backward compatibility with optional validation logic.
…test file exclusions

This change adds type definitions for Vitest and Testing Library to the todo-app's TypeScript configuration. Additionally, it removes the exclusion of test files from the build process, allowing for better integration with testing tools.
@jaruesink jaruesink merged commit 073512b into codegen-bot/persist-todos-localstorage-STA-2-1754688724 Aug 9, 2025
1 check passed
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.

2 participants