Skip to content

Add coverage for useViewportOffset hook behavior - #16

Merged
itsubaki merged 4 commits into
mainfrom
copilot/add-tests-for-hooks-use-viewport-offset
Apr 3, 2026
Merged

Add coverage for useViewportOffset hook behavior#16
itsubaki merged 4 commits into
mainfrom
copilot/add-tests-for-hooks-use-viewport-offset

Conversation

Copilot AI commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Adds focused tests for hooks/use-viewport-offset.ts to cover the hook’s viewport-driven state updates and fallback behavior. The new coverage exercises the cases most likely to regress when visualViewport is absent or when mobile viewport metrics change.

  • Hook coverage

    • adds a dedicated use-viewport-offset.test.tsx
    • verifies the hook returns 0 when window.visualViewport is unavailable
    • verifies initial offset calculation from innerHeight, visualViewport.height, and offsetTop
  • Viewport event behavior

    • verifies offset updates when mocked resize and scroll events fire
    • verifies negative computed offsets are clamped to 0
  • Lifecycle behavior

    • verifies the hook unregisters the same viewport listeners on unmount
  • Mocking approach

    • uses a lightweight mocked visualViewport with explicit listener registration and dispatch to keep the tests deterministic and close to the browser API surface
const viewport = createVisualViewport(800, 50)
setVisualViewport(viewport)

const { result } = renderHook(() => useViewportOffset())

act(() => {
  viewport.height = 900
  viewport.offsetTop = 20
  viewport.dispatch("resize")
})

expect(result.current).toBe(80)

Copilot AI and others added 4 commits April 3, 2026 11:30
Agent-Logs-Url: https://github.com/itsubaki/bloch/sessions/320862b5-e8b1-4454-9c70-95e9aeedfbf8

Co-authored-by: itsubaki <1759459+itsubaki@users.noreply.github.com>
Agent-Logs-Url: https://github.com/itsubaki/bloch/sessions/320862b5-e8b1-4454-9c70-95e9aeedfbf8

Co-authored-by: itsubaki <1759459+itsubaki@users.noreply.github.com>
Agent-Logs-Url: https://github.com/itsubaki/bloch/sessions/320862b5-e8b1-4454-9c70-95e9aeedfbf8

Co-authored-by: itsubaki <1759459+itsubaki@users.noreply.github.com>
Agent-Logs-Url: https://github.com/itsubaki/bloch/sessions/320862b5-e8b1-4454-9c70-95e9aeedfbf8

Co-authored-by: itsubaki <1759459+itsubaki@users.noreply.github.com>
@vercel

vercel Bot commented Apr 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
bloch Ready Ready Preview, Comment, Open in v0 Apr 3, 2026 11:59am

@itsubaki
itsubaki marked this pull request as ready for review April 3, 2026 11:59
@itsubaki
itsubaki merged commit f3210f1 into main Apr 3, 2026
3 checks passed
@itsubaki
itsubaki deleted the copilot/add-tests-for-hooks-use-viewport-offset branch April 3, 2026 12:00
@codecov

codecov Bot commented Apr 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b8e8063) to head (8631207).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #16   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         9    +1     
  Lines           63        77   +14     
  Branches        11        12    +1     
=========================================
+ Hits            63        77   +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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