Skip to content

test: coverage for partyDisplayName and analytics path helpers#70

Open
doolin wants to merge 1 commit into
EasyDynamics:mainfrom
doolin:contrib/cookie-party-helper-coverage
Open

test: coverage for partyDisplayName and analytics path helpers#70
doolin wants to merge 1 commit into
EasyDynamics:mainfrom
doolin:contrib/cookie-party-helper-coverage

Conversation

@doolin

@doolin doolin commented May 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds 18 unit tests against three pure helpers. No React rendering,
no fetch mocking, no provider wrappers — just pure functions in,
expected values out.

Helpers exercised:

  • `partyDisplayName` in `src/utils/partyDisplay.ts` (7 cases) —
    undefined-input fallback, string-uuid passthrough, the
    `name → short-name → uuid` resolution order, and the empty-string
    name edge case.
  • `sanitizedAnalyticsPath` in `src/hooks/useCookieConsent.ts`
    (6 cases) — the `url` parameter masking, other-param preservation,
    hash handling, and the no-search-no-hash passthrough.
  • `viewerAnalyticsPath` in `src/hooks/useCookieConsent.ts`
    (5 cases) — `view` parameter injection, `url` masking, overwrite
    of any existing `view` value.

Why these helpers

Both source files have low historical churn (1 and 2 commits each)
so the tests should stay valid across ongoing refactors. The two
analytics-path functions also encode a privacy-relevant invariant —
that loaded document URLs never leave the browser as analytics
data — which is worth locking in with assertions.

Independence

No dependency on the coverage-tooling PR (#68). These tests run
under the existing `npm test` (vitest run from #65) without any
config changes.

Test plan

  • `npm ci` from a clean checkout of `main`
  • `npm test -- --run` → 23 passing (5 pre-existing + 18 new)
  • No product-code changes

@doolin doolin requested a review from pjavan as a code owner May 24, 2026 12:37
@doolin

doolin commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

I will continue with low-churn coverage for now, then having a good base, gradually start adding coverage to files with more historical churn.

18 unit tests against three pure helpers — no React rendering, no
fetch mocking, no provider wrappers:

- src/utils/partyDisplay.ts — partyDisplayName() (7 cases). Tests
  the undefined-input fallback, string-uuid passthrough, and the
  name → short-name → uuid resolution order.
- src/hooks/useCookieConsent.ts — sanitizedAnalyticsPath() (6 cases)
  and viewerAnalyticsPath() (5 cases). Tests the 'url' parameter
  masking, search-param preservation, hash handling, and viewId
  injection.

Both target files have low historical churn (1 and 2 commits each),
so the tests should remain stable across ongoing refactors.

23 tests passing on a clean checkout of main after npm ci.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@doolin doolin force-pushed the contrib/cookie-party-helper-coverage branch from 2b0e123 to e9c5721 Compare May 28, 2026 22:56
@doolin

doolin commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main to pick up the merged fork-PR conditional from #69 — Azure check should now skip cleanly on this branch.

@doolin

doolin commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

ty

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