Skip to content

Add tests for network quality hook - #409

Closed
kanaksahu111 wants to merge 5 commits into
TheVicky1:mainfrom
kanaksahu111:main
Closed

kanaksahu111 wants to merge 5 commits into
TheVicky1:mainfrom
kanaksahu111:main

Conversation

@kanaksahu111

Copy link
Copy Markdown

🏛️ PACT Pull Request

1. Related Issue

Closes #404


2. Summary of Changes

Implemented a reusable network quality detection hook.

  • Detects online/offline status
  • Reads connection type (4g, 3g, 2g, slow-2g)
  • Detects Data Saver mode
  • Identifies slow connections
  • Listens for browser online/offline events and connection changes
  • Added automated tests covering network quality detection and state changes

3. Motivation & Context

Applications can provide a better user experience when they know whether the user is offline or connected through a slower network.

This hook provides a reusable way for the application to detect network quality and react to connection changes.


4. Implementation Details

  • Added src/hooks/use-network-quality.ts
  • Uses navigator.onLine for online/offline status
  • Uses the Network Information API when available
  • Falls back to unknown connection type when Network Information API data is unavailable
  • Detects slow connections based on 2g, slow-2g, and saveData
  • Subscribes to online, offline, and connection change events
  • Added tests/use-network-quality.test.ts with mocked browser APIs

5. Testing & Local Validation

  • npm run lint — ESLint passed with 0 errors
  • npx tsc --noEmit — TypeScript strict check passed with 0 errors
  • npm test (or node scratch/run-tests.mjs) — test matrix passed
  • npm run test:file -- <file> — targeted test suite passed
  • node scratch/secret-scan.mjs — Zero secrets or sensitive credentials detected
  • npm run build — Production build succeeded without errors

Testing was not run locally because the contribution was made through the GitHub web editor.


6. UI & Visual Changes

  • No UI changes (This PR does not alter visual styling, layout, or components)

7. Database & Security Impact

  • No database or security-sensitive changes

8. Documentation Impact

  • Documentation updated to reflect changes
  • Documentation updates not required for this change

9. Contributor Quality Checklist

  • 🌱 Micro-Contribution Fast-Path: This is a targeted Good First Issue / 5–30 minute micro-change (single file, verified locally).
  • My PR has a single, focused scope (avoiding unrelated formatting or refactoring.
  • I have read and followed PACT's Contributing Guide.
  • I confirm that zero secrets, API keys, private tokens, or .env.local files are included in this PR.
  • My branch was created from the latest upstream/main with an appropriate prefix (e.g., feat/, fix/, docs/, ui/).
  • My commits follow the Conventional Commits format (type(scope): description).
  • I have linked the target issue in Section 1 above.
  • I have reviewed my own git diff to ensure no stray files or debugging artifacts were committed.

10. Reviewer Notes

The implementation follows the existing browser-hook pattern in the repository and keeps the network detection logic reusable for future features.

@vercel

vercel Bot commented Oct 6, 2026

Copy link
Copy Markdown

@kanaksahu111 is attempting to deploy a commit to the Vicky's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

👋 Welcome to PACT OS, @kanaksahu111! 🚀

Thank you for taking the time to open your first pull request on PACT! We are thrilled to have you here in our open-source community.


🔍 What Happens Next?

  1. Automated Verification: Our Continuous Integration (CI) workflow is currently verifying:
    • 🔒 Zero-Secret Security Scan
    • 🔗 Markdown Link Integrity
    • 🧹 ESLint Code Quality
    • 🏷️ TypeScript Strict Typecheck
    • 🧪 56-Suite Automated Domain & Security Test Matrix
    • 🏗️ Next.js Production Build
  2. Maintainer Review: A maintainer (@TheVicky1) will review your pull request shortly.
  3. Friendly Iteration: If any adjustments or feedback are needed, we will provide clear, actionable suggestions to help get your PR merged smoothly.

📚 Helpful Quick Links

Thank you for helping make PACT better! Plan. Track. Improve. Repeat. 🏛️✨

@TheVicky1 TheVicky1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The workflow didn't passed kindly check it and raise a new PR.

Thanks!

@TheVicky1 TheVicky1 closed this Oct 6, 2026
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.

[DX] Implement Custom Network Connection Quality Detection Hook

2 participants