Skip to content

test: add unit tests across pure utilities, forms, and ORCID helpers#880

Open
thostetler wants to merge 9 commits into
adsabs:masterfrom
thostetler:test/coverage-improvements
Open

test: add unit tests across pure utilities, forms, and ORCID helpers#880
thostetler wants to merge 9 commits into
adsabs:masterfrom
thostetler:test/coverage-improvements

Conversation

@thostetler

@thostetler thostetler commented Jun 3, 2026

Copy link
Copy Markdown
Member

Overall test coverage was at 62.57%. This adds 156 new tests across 11 files targeting the lowest-coverage areas with deterministic, pure-function behavior.

  • graphUtils, visualization utils, ORCID models, EmailNotifications/Utils, useNivoDarkTheme

  • KeywordsForm, CitationForm, orcid API key helpers, useBubblePlot

  • ArxivForm category toggle/submit collapsing, useRemoveWorks pure helpers

  • ORCID helpers (convertDocType, findWorkInProfile, mergeOrcidMissingRecords), QueryForm state machine

  • change it to test to try to normalize the naming scheme were using

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.1%. Comparing base (6a15785) to head (ae5c8fe).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #880     +/-   ##
========================================
+ Coverage    61.2%   64.1%   +2.9%     
========================================
  Files         348     349      +1     
  Lines       41373   41389     +16     
  Branches     1826    2019    +193     
========================================
+ Hits        25297   26504   +1207     
+ Misses      16033   14842   -1191     
  Partials       43      43             
Files with missing lines Coverage Δ
src/components/AbstractSources/linkGenerator.ts 89.1% <100.0%> (+2.1%) ⬆️
src/components/AbstractSources/openUrlGenerator.ts 82.5% <100.0%> (ø)
...omponents/Metatags/json-ld-abstract/identifiers.ts 92.7% <100.0%> (+0.1%) ⬆️
src/utils/common/encodeDOI.ts 100.0% <100.0%> (ø)

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thostetler thostetler requested a review from Copilot June 3, 2026 14:49
@thostetler thostetler marked this pull request as ready for review June 3, 2026 14:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR primarily increases unit test coverage across low-coverage, deterministic areas (pure utilities, visualization transforms, ORCID helpers, and EmailNotification forms). It also introduces/adjusts URL-encoding behavior for DOI/OpenURL generation to ensure generated links are safe for use in URL paths and query strings.

Changes:

  • Added extensive Vitest coverage for visualization utils, ORCID helpers/models, EmailNotification forms, and theme/hooks.
  • Introduced encodeDOIPath and applied DOI-safe path encoding to DOI links in JSON-LD metatags and ADS gateway DOI URLs.
  • Updated OpenURL query construction to encode query parameter values (and adjusted tests accordingly).

Risk summary

Medium risk: one production helper (createUrlByType) now uses DOI-specific encoding for all identifier types, which can produce malformed gateway URLs for non-DOI identifiers in edge cases.

Findings (priority order)

medium

  1. Non-DOI identifiers may be encoded incorrectly in gateway links
  • Impact: Gateway URLs generated for non-DOI identifier types (e.g., arXiv) may end up with unintended path segmentation (notably when identifiers contain /, such as legacy arXiv IDs). This can break outbound links in the Abstract details UI.
  • Location: src/components/AbstractSources/linkGenerator.ts (createUrlByType, around lines 141–144)
  • Minimal fix: Encode DOI identifiers with encodeDOIPath, but encode all other identifiers with encodeURIComponent, and also encodeURIComponent the bibcode for consistency.
  • Confidence: high
  1. QueryForm Select mock can pass undefined to onChange (type-check/runtime hazard)
  • Impact: The test mock can fail TypeScript checking and (in edge cases) can call onChange(undefined), diverging from the component’s expected onChange shape.
  • Location: src/components/EmailNotifications/Forms/QueryForm.test.tsx (mocked Select onChange, around line 47)
  • Minimal fix: Use a non-null assertion (!) or handle the undefined case explicitly.
  • Confidence: high

low
3) Misleading test description for percent encoding behavior

  • Impact: Test name/comment suggests “no double-encoding,” but the expectation demonstrates percent (%) is encoded to %25 (so %23 becomes %2523). This can confuse future maintainers.
  • Location: src/utils/common/__tests__/encodeDOI.test.ts (around lines 27–30)
  • Minimal fix: Rename the test to accurately describe encoding literal %.
  • Confidence: high

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/utils/common/encodeDOI.ts Adds encodeDOIPath utility for DOI-safe URL path encoding (preserving /).
src/utils/common/tests/encodeDOI.test.ts Unit tests for encodeDOIPath covering reserved characters and % handling.
src/lib/useNivoDarkTheme.test.ts Tests expected Nivo dark theme structure and specific colors.
src/lib/orcid/useRemoveWorks.test.ts Tests pure helpers used by useRemoveWorks (fulfilled/rejected extraction, putcode lookup).
src/lib/orcid/helpers.test.ts Tests ORCID helper functions (doc type conversion, profile lookup, merge behavior).
src/components/Visualizations/utils/utils.test.ts Tests visualization utility functions (ticks, grouping, query wrapping).
src/components/Visualizations/utils/graphUtils.test.ts Large unit test suite for graph data transformers and plotting utilities.
src/components/Visualizations/Graphs/useBubblePlot.test.tsx Hook tests for scale construction, theming, and edge cases (empty data/log scales).
src/components/Metatags/json-ld-abstract/identifiers.ts Uses encodeDOIPath when generating DOI sameAs URLs.
src/components/Metatags/json-ld-abstract/tests/identifier.test.ts Adds test ensuring DOI sameAs URL encodes reserved characters.
src/components/EmailNotifications/Forms/Utils.test.tsx Tests keyword validation helper behavior.
src/components/EmailNotifications/Forms/QueryForm.test.tsx Tests QueryForm submission/state machine and vault search integration (mocked).
src/components/EmailNotifications/Forms/KeywordsForm.test.tsx Tests keyword form debounce validation and submit behavior.
src/components/EmailNotifications/Forms/CitationForm.test.tsx Tests citation form validation and mutation payload construction.
src/components/EmailNotifications/Forms/ArxivForm.test.tsx Tests arXiv category selection UX and submission payload collapsing.
src/components/AbstractSources/openUrlGenerator.ts Encodes OpenURL query parameter values with encodeURIComponent (behavior change).
src/components/AbstractSources/linkGenerator.ts Uses DOI-safe encoding for identifiers when building gateway URLs (behavior change).
src/components/AbstractSources/tests/openUrlGenerator.test.ts Adds OpenURL encoding regression test for # in DOI.
src/components/AbstractSources/tests/linkGenerator.test.ts Updates expected OpenURL strings to match encoded query values.
src/components/AbstractSources/tests/createUrlByType.test.ts New tests verifying DOI encoding behavior in gateway DOI links.
src/api/orcid/orcid.test.ts Tests ORCID React Query key construction (ensuring user/token excluded).
src/api/orcid/models.test.ts Tests ORCID validators (IDs, user objects, profile entry shape).

Comment thread src/components/AbstractSources/linkGenerator.ts
Comment thread src/utils/common/__tests__/encodeDOI.test.ts Outdated
Comment thread src/components/EmailNotifications/Forms/QueryForm.test.tsx
@thostetler thostetler force-pushed the test/coverage-improvements branch from dc68700 to feb19e7 Compare June 8, 2026 16:13
@thostetler thostetler requested a review from shinyichen June 9, 2026 17:00
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