Skip to content

Reduce test coverage redundancies, audit docstrings#59

Open
alex-rawlings-yyc wants to merge 4 commits into
mainfrom
reduce-coverage-redundancies
Open

Reduce test coverage redundancies, audit docstrings#59
alex-rawlings-yyc wants to merge 4 commits into
mainfrom
reduce-coverage-redundancies

Conversation

@alex-rawlings-yyc
Copy link
Copy Markdown
Contributor

@alex-rawlings-yyc alex-rawlings-yyc commented May 12, 2026

This change is Reviewable

Summary by CodeRabbit

  • Tests

    • Added TokenChip unit tests and expanded coverage across components, hooks, and parsers to catch more edge cases.
  • Bug Fixes

    • Improved validation and error reporting for malformed/duplicate data and parsing edge cases.
  • Documentation

    • Enhanced inline docs and JSDoc across components, hooks, parsers, and type definitions for clarity and maintainability.

Review Change Stack

@alex-rawlings-yyc alex-rawlings-yyc added the up next Auto adds an issue to the PT Lexical Extensions project label May 12, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Warning

Rate limit exceeded

@alex-rawlings-yyc has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 57 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b9abdb16-654a-460f-87ac-6521681acdbc

📥 Commits

Reviewing files that changed from the base of the PR and between 8a09c00 and 7e997a5.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (23)
  • __mocks__/papi-frontend-react.ts
  • src/__tests__/components/ContinuousView.test.tsx
  • src/__tests__/components/Interlinearizer.test.tsx
  • src/__tests__/components/InterlinearizerLoader.test.tsx
  • src/__tests__/components/SegmentView.test.tsx
  • src/__tests__/components/TokenChip.test.tsx
  • src/__tests__/hooks/useInterlinearizerBookData.test.ts
  • src/__tests__/hooks/useOptimisticBooleanSetting.test.ts
  • src/__tests__/main.test.ts
  • src/__tests__/parsers/papi/bookTokenizer.test.ts
  • src/__tests__/parsers/papi/usjBookExtractor.test.ts
  • src/__tests__/parsers/pt9/interlinearXmlParser.test.ts
  • src/components/ContinuousView.tsx
  • src/components/Interlinearizer.tsx
  • src/components/InterlinearizerLoader.tsx
  • src/components/ScriptureNavControls.tsx
  • src/components/SegmentView.tsx
  • src/hooks/useInterlinearizerBookData.ts
  • src/main.ts
  • src/parsers/papi/bookTokenizer.ts
  • src/parsers/papi/usjBookExtractor.ts
  • src/parsers/pt9/interlinearXmlParser.ts
  • src/types/interlinearizer.d.ts
📝 Walkthrough

Walkthrough

Refactors tests to mock higher-level hooks and capture SegmentView props, tightens the useProjectData mock, adds Readonly prop typings and explicit hook interfaces, expands parser tests, and enriches JSDoc across the codebase.

Changes

Testing Infrastructure and Assertion Strategy

Layer / File(s) Summary
Mock Validation and Whitelist Enforcement
__mocks__/papi-frontend-react.ts
useProjectData mock now validates provider method names against KNOWN_PROJECT_DATA_METHODS and throws descriptive errors for unknown accesses.
InterlinearizerLoader Test Hook Mocking
src/__tests__/components/InterlinearizerLoader.test.tsx
Refactored to mock useInterlinearizerBookData and useOptimisticBooleanSetting, using helpers to parameterize mocked state and asserting hook call arguments for stability and continuous-scroll wiring.
Interlinearizer SegmentView Props Capture and Assertion
src/__tests__/components/Interlinearizer.test.tsx
Shifted from token-chip text assertions to capturing SegmentView component props (segment, isActive, displayMode, onClick) and validating parent-child contracts, click handlers, and prop propagation.
Component Mock and Fixture Enhancements
src/__tests__/components/ContinuousView.test.tsx, src/__tests__/components/SegmentView.test.tsx
Improved mocks for PhraseBox and TokenChip with typed props and token rendering, clarified fixture documentation describing behavioral edge cases.
TokenChip Unit Test Suite
src/__tests__/components/TokenChip.test.tsx
New test suite covering text rendering, conditional tw-border class for word vs punctuation tokens, and DOM structure validation.

Parser Test Coverage Expansion

Layer / File(s) Summary
USJ Book Extractor Test Coverage
src/__tests__/parsers/papi/usjBookExtractor.test.ts
Extended with assertions for contentHash stability across writing systems, mid-verse heading paragraph handling, nested inline char traversal, and duplicate verse SID error detection.
Book Tokenizer Test Validation
src/__tests__/parsers/papi/bookTokenizer.test.ts
Updated with fixture documentation, stronger token-ID uniqueness assertions, and parameterized malformed SID validation covering multiple invalid inputs.
InterlinearXmlParser Test Coverage
src/__tests__/parsers/pt9/interlinearXmlParser.test.ts
Expanded with parameterized <Excluded> tests, multiple <Punctuation> entry validation, refined error message assertions, invalid-range parameterized coverage, and non-boolean value handling.

Type Safety and Component Props

Layer / File(s) Summary
Component Props Readonly Annotations
src/components/Interlinearizer.tsx, src/components/InterlinearizerLoader.tsx
Wrapped component prop object types in Readonly<...> to enforce immutability contracts in the TypeScript type system.
Hook Type Interface Extraction
src/hooks/useInterlinearizerBookData.ts
Extracted explicit UseInterlinearizerBookDataArgs and UseInterlinearizerBookDataResult TypeScript interfaces with JSDoc, replacing inline type declarations.

Documentation and JSDoc Expansion

Layer / File(s) Summary
Component Implementation Documentation and Code Refinement
src/components/ContinuousView.tsx, src/components/SegmentView.tsx, src/components/ScriptureNavControls.tsx
Added JSDoc for helpers and constants, refactored optional chaining for safer null handling (lastInternal?.book), and expanded display mode and component purpose documentation.
Function Error Documentation
src/main.ts, src/parsers/papi/bookTokenizer.ts, src/parsers/papi/usjBookExtractor.ts, src/parsers/pt9/interlinearXmlParser.ts
Documented @throws conditions for API functions and parser methods, covering validation failures, propagated errors, and specific error shapes.
Type Definition and Contract Documentation
src/types/interlinearizer.d.ts
Expanded JSDoc across data model types clarifying semantic meaning, invariants, field availability conditions, and mutual-exclusivity rules for MultiString, ScriptureRef, Lexicon references, Token, Morpheme, Phrase, and alignment structures.

Possibly related PRs

Suggested labels

🟪Idea

Suggested reviewers

  • imnasnainaec
  • jasonleenaylor

"🐇
I nudge the mocks, I tidy the types,
I hum JSDoc lines in gentle flights.
Tests now catch props with keener eyes,
Docs sing truths where ambiguity lies.
Hooray—tiny hops and brighter nights!"

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Reduce test coverage redundancies, audit docstrings' directly and accurately summarizes the two main objectives of this PR: removing redundant tests and improving documentation.
Docstring Coverage ✅ Passed Docstring coverage is 96.30% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch reduce-coverage-redundancies

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@alex-rawlings-yyc alex-rawlings-yyc self-assigned this May 12, 2026
@alex-rawlings-yyc alex-rawlings-yyc marked this pull request as ready for review May 12, 2026 18:13
Copy link
Copy Markdown
Contributor

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

@imnasnainaec reviewed 15 files and all commit messages, and made 4 comments.
Reviewable status: 15 of 22 files reviewed, 1 unresolved discussion (waiting on alex-rawlings-yyc).


a discussion (no related file):
The mocking of PhraseBox and TokenChip in the *View.text.tsx files make me hesitant about #60. I like the idea of making sure unit tests only touch the file being tested. That keeps things consistent, modular, and organized. But it can be nice to test the interaction with a component and its child components for partial integration testing. Do we want to add extra test structure that results in more unit tests and less integration test coverage?

My concern is less relevant if we have some broader e2e and/or integration testing set up.

Wherever we do mock out components that are used by multiple other components, we may want the mocks to be defined just once for reuse.


src/__tests__/parsers/papi/usjBookExtractor.test.ts line 23 at r1 (raw file):

  });

  it('produces a stable contentHash independent of writingSystem', () => {

This test is fine, but I don't think we need to be generally zealous combining the yes and no cases of a situation into a single test.


src/__tests__/parsers/pt9/interlinearXmlParser.test.ts line 849 at r1 (raw file):

            name: 'SyntaxError',
            message: expect.stringContaining(
              'Invalid XML: Range missing or invalid Index/Length attributes (must be non-negative integers)',

⛏️ "Range missing" doesn't appear relevant to this test.


src/types/interlinearizer.d.ts line 796 at r1 (raw file):

   * the phrase is a multi-word lexical entry — the Lexicon extension supports both kinds via
   * `IEntry.morphType = Phrase` (contiguous) or `DiscontiguousPhrase` (e.g. "ne … pas"). Exactly
   * one of `gloss` or `senseRef` may be set; setting both is a TypeScript type error. Omitting both

This won't be correct after #33

Copy link
Copy Markdown
Contributor Author

@alex-rawlings-yyc alex-rawlings-yyc left a comment

Choose a reason for hiding this comment

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

@alex-rawlings-yyc made 2 comments.
Reviewable status: 15 of 22 files reviewed, 1 unresolved discussion (waiting on alex-rawlings-yyc and imnasnainaec).


a discussion (no related file):

Previously, imnasnainaec (D. Ror.) wrote…

The mocking of PhraseBox and TokenChip in the *View.text.tsx files make me hesitant about #60. I like the idea of making sure unit tests only touch the file being tested. That keeps things consistent, modular, and organized. But it can be nice to test the interaction with a component and its child components for partial integration testing. Do we want to add extra test structure that results in more unit tests and less integration test coverage?

My concern is less relevant if we have some broader e2e and/or integration testing set up.

Wherever we do mock out components that are used by multiple other components, we may want the mocks to be defined just once for reuse.

I would prefer if we kept integration tests and unit tests pretty separate. However, I don't have a lot of experience in this regard, so I think we should get a good idea of what works best in practice. I just love modularity and dislike the conceptual uncleanliness of coverage overlap. However, coverage overlap may not be as messy or as redundant as I think it is. The output of a coverage tool doesn't capture a lot of the nuances of unit testing and I may be far too focused on having nice numbers and conceptual boundaries.

I think we should discuss this more on Thursday and try to come to a conclusion there.


src/types/interlinearizer.d.ts line 796 at r1 (raw file):

Previously, imnasnainaec (D. Ror.) wrote…

This won't be correct after #33

I'll make sure this is addressed there rather than preemptively updating it here.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/__tests__/hooks/useInterlinearizerBookData.test.ts (1)

1-1: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Fix Prettier formatting errors before merge.

The pipeline reports that prettier --check failed. Run prettier --write . to fix formatting issues across all files in this PR.

🤖 Prompt for 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.

In `@src/__tests__/hooks/useInterlinearizerBookData.test.ts` at line 1, Prettier
formatting failed for this PR; run the formatter across the repo (e.g., execute
`prettier --write .`) and commit the resulting changes so tests pass;
specifically ensure the test file useInterlinearizerBookData.test.ts and any
other modified files are reformatted and re-committed to resolve the `prettier
--check` failure.
🧹 Nitpick comments (1)
__mocks__/papi-frontend-react.ts (1)

22-22: 💤 Low value

Consider typing prop as string | symbol for Proxy correctness.

The Proxy get trap's property parameter can be either a string or a symbol. While string-only typing works for current usage, using prop: string | symbol would be more precise.

♻️ More precise typing
-      get(_target, prop: string) {
+      get(_target, prop: string | symbol) {
+        if (typeof prop !== 'string') {
+          throw new Error(`useProjectData mock: symbol properties not supported.`);
+        }
         if (KNOWN_PROJECT_DATA_METHODS.has(prop)) {
🤖 Prompt for 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.

In `@__mocks__/papi-frontend-react.ts` at line 22, The Proxy get trap in
__mocks__/papi-frontend-react.ts currently types the property parameter as prop:
string but must accept symbols too; update the get(_target, prop: string)
signature to prop: string | symbol to match the ProxyHandler.get definition and
ensure correct typing across symbol property access in the mock. Reference the
get trap function in this mock and adjust all related usage or type assertions
to accommodate prop being string | symbol.
🤖 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.

Outside diff comments:
In `@src/__tests__/hooks/useInterlinearizerBookData.test.ts`:
- Line 1: Prettier formatting failed for this PR; run the formatter across the
repo (e.g., execute `prettier --write .`) and commit the resulting changes so
tests pass; specifically ensure the test file useInterlinearizerBookData.test.ts
and any other modified files are reformatted and re-committed to resolve the
`prettier --check` failure.

---

Nitpick comments:
In `@__mocks__/papi-frontend-react.ts`:
- Line 22: The Proxy get trap in __mocks__/papi-frontend-react.ts currently
types the property parameter as prop: string but must accept symbols too; update
the get(_target, prop: string) signature to prop: string | symbol to match the
ProxyHandler.get definition and ensure correct typing across symbol property
access in the mock. Reference the get trap function in this mock and adjust all
related usage or type assertions to accommodate prop being string | symbol.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 96f39dd1-7677-4e35-86ff-bf285db6b441

📥 Commits

Reviewing files that changed from the base of the PR and between 4fa1343 and d56c6af.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (23)
  • __mocks__/papi-frontend-react.ts
  • src/__tests__/components/ContinuousView.test.tsx
  • src/__tests__/components/Interlinearizer.test.tsx
  • src/__tests__/components/InterlinearizerLoader.test.tsx
  • src/__tests__/components/SegmentView.test.tsx
  • src/__tests__/components/TokenChip.test.tsx
  • src/__tests__/hooks/useInterlinearizerBookData.test.ts
  • src/__tests__/hooks/useOptimisticBooleanSetting.test.ts
  • src/__tests__/main.test.ts
  • src/__tests__/parsers/papi/bookTokenizer.test.ts
  • src/__tests__/parsers/papi/usjBookExtractor.test.ts
  • src/__tests__/parsers/pt9/interlinearXmlParser.test.ts
  • src/components/ContinuousView.tsx
  • src/components/Interlinearizer.tsx
  • src/components/InterlinearizerLoader.tsx
  • src/components/ScriptureNavControls.tsx
  • src/components/SegmentView.tsx
  • src/hooks/useInterlinearizerBookData.ts
  • src/main.ts
  • src/parsers/papi/bookTokenizer.ts
  • src/parsers/papi/usjBookExtractor.ts
  • src/parsers/pt9/interlinearXmlParser.ts
  • src/types/interlinearizer.d.ts

@alex-rawlings-yyc
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@imnasnainaec imnasnainaec left a comment

Choose a reason for hiding this comment

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

@imnasnainaec reviewed 8 files and all commit messages, and resolved 1 discussion.
Reviewable status: 19 of 24 files reviewed, all discussions resolved (waiting on alex-rawlings-yyc).

@alex-rawlings-yyc alex-rawlings-yyc force-pushed the reduce-coverage-redundancies branch from 2f2b34e to 7e997a5 Compare May 13, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

up next Auto adds an issue to the PT Lexical Extensions project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants