Skip to content

chrome(nav): extract handleNavClick modifier guard into a pure testable predicate #120

@yigitdot

Description

@yigitdot

Follow-up from the PR #118 review. Mirrors the #114#117 precedent (pure extraction for testability).

Background

components/site/Chrome.tsx handleNavClick opens with a 6-flag short-circuit:

if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;

homeHashSectionId is already extracted + unit-tested (lib/scroll.test.ts), so the only remaining untested decision in the handler is this modifier guard — generic browser-nav etiquette, not #116 logic. The repo has no jsdom / RTL, so the DOM glue (getElementById / scrollIntoView / replaceState / location.assign) intentionally stays untested; this predicate, however, is trivially pure.

Suggested change

// lib/scroll.ts (or a sibling)
export function shouldInterceptNavClick(e: {
  defaultPrevented: boolean; button: number;
  metaKey: boolean; ctrlKey: boolean; shiftKey: boolean; altKey: boolean;
}): boolean {
  return !(e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey);
}

handleNavClick calls it; add a lib/scroll.test.ts block covering: plain left-click → true; each modifier / middle-click / defaultPrevented → false. Zero new infra (Node-env Vitest, existing **/*.test.ts glob). Not blocking — defer until convenient.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions