Skip to content

YPE-1157: test(hooks) - useChapterNavigation#185

Closed
cameronapak wants to merge 5 commits intomainfrom
cp/YPE-1157-react-sdk-hooks-use-chapter-navigation-tests
Closed

YPE-1157: test(hooks) - useChapterNavigation#185
cameronapak wants to merge 5 commits intomainfrom
cp/YPE-1157-react-sdk-hooks-use-chapter-navigation-tests

Conversation

@cameronapak
Copy link
Collaborator

@cameronapak cameronapak commented Mar 3, 2026

Rewrites useChapterNavigation.test.tsx from 7 tests to 19, covering: boundary navigation (Bible start/end), middle-chapter bidirectional nav, cross-book transitions, intro chapter handling, loading state, empty books array, currentChapterIndex calculation, and no-op edge cases.

93%+ statement coverage, 100% function/line coverage.

Completes YPE-1157

Rewrite useChapterNavigation tests with 19 cases covering boundary
navigation, cross-book nav, intro chapters, loading/empty states,
currentChapterIndex, and edge cases. 93%+ statement coverage.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

⚠️ No Changeset found

Latest commit: c94aeb9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR rewrites useChapterNavigation.test.tsx, expanding coverage from 7 to 19 tests with meaningful scenario differentiation across all major code paths in the hook. The changes are test-only and carry no production risk.

Key improvements:

  • setMockBooks helper centralises mock setup, making per-test overrides clear and reducing boilerplate
  • createWrapper rename from wrapper correctly signals that it is a factory function
  • The loading test now uses setMockBooks(allBooks, true) (non-empty books + loading flag), isolating booksLoading as the sole reason canNavigateNext/canNavigatePrevious are false
  • Symmetric no-op coverage: both navigateToNext and navigateToPrevious are now tested when books is empty
  • The final edge-case test name ('navigateToNext is no-op when next book has no canonical chapters') describes the scenario rather than an internal guard, making intent clear
  • currentChapterIndex edge cases are covered for both a chapter absent from the chapters list and a book with chapters: undefined
  • All four issues from previous review rounds have been resolved

Confidence Score: 5/5

  • Test-only file with no production code modifications — entirely safe to merge.
  • This PR touches only the test file with no changes to production code. The test suite is well-structured with clear naming, logical soundness, and proper isolation of concerns. All four issues flagged in prior review rounds have been conclusively resolved: duplicate tests eliminated, symmetric no-op coverage added for both navigation directions with empty books, test naming corrected to describe scenarios rather than internal guards, and the loading test properly isolates the loading flag using a non-empty books array. The setMockBooks/createWrapper pattern ensures each test starts from a clean, predictable state. Coverage metrics exceed 93% statements with 100% function/line coverage.
  • No files require special attention.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[navigateToNext / navigateToPrevious] --> B{getAdjacentChapter<br/>returns null?}
    B -->|yes - boundary reached| C[no-op]
    B -->|no| D[navigate result]
    D --> E{result is null OR<br/>booksData empty?}
    E -->|yes| C
    E -->|no| F[Find targetBook<br/>in booksData]
    F --> G{targetBook<br/>found?}
    G -->|no| C
    G -->|yes| H[Find targetChapter<br/>in chapters OR intro]
    H --> I{targetChapter<br/>found?}
    I -->|no - e.g. next book has<br/>no canonical chapters| C
    I -->|yes| J{Different book?}
    J -->|yes| K[setBook + setChapter]
    J -->|no| L[setChapter only]

    style C fill:#f9f,stroke:#333
    style K fill:#9f9,stroke:#333
    style L fill:#9f9,stroke:#333
Loading

Last reviewed commit: c94aeb9

…no-op case

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cameronapak
Copy link
Collaborator Author

@greptile, please re-review this again. Update your previous review when complete

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cameronapak
Copy link
Collaborator Author

@greptile the reptile, please re-re-review this PR against the latest changes. Then, update the PR description

…ooks array

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cameronapak
Copy link
Collaborator Author

@greptile, please re-re-re-review this PR. Update the PR comment with your updates.

@cameronapak cameronapak self-assigned this Mar 3, 2026
@cameronapak
Copy link
Collaborator Author

Even though I spent time doing this, I will close this because in #187 I realized it's not needed and not used. Therefore it's getting deprecated.

@cameronapak cameronapak closed this Mar 4, 2026
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