Skip to content

Add unit tests for the shared ScrollToTop scroll + focus-management behavior #177

Description

@Jagadeeshftw

📌 Description

ScrollToTop (src/shared/components/ScrollToTop.tsx) scrolls to top on route change and moves focus to #main (falling back to skip-target/body) while honoring prefers-reduced-motion, but its logic is untested.

💡 Why it matters: Route-change focus and scroll behavior is easy to regress and affects accessibility.

🧩 Requirements and context

  • Test scroll-to-top on pathname change.
  • Test focus moves to #main, then skip-target, then body when targets are missing.
  • Test smooth vs instant scroll under prefers-reduced-motion.
  • Test that hash-only changes are ignored.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

🛠️ Suggested execution

1. Fork the repo and create a branch

git checkout -b test/scrolltotop

2. Implement changes

  • Write/modify the relevant source: minor TSDoc on src/shared/components/ScrollToTop.tsx
  • Write comprehensive tests: src/shared/components/ScrollToTop.test.tsx
  • Add documentation: inline TSDoc
  • Include TSDoc doc comments
  • Validate security assumptions: n/a

3. Test and commit

  • Run tests:
npm run test
  • Cover edge cases: missing #main, reduced motion, hash navigation
  • Include test output and security notes in the PR description.

Example commit message

test(scrolltotop): cover scroll and focus fallbacks

✅ Acceptance criteria

  • Scroll-on-route-change tested
  • Focus fallback chain tested
  • Reduced-motion branch tested
  • Hash-change ignore tested

🔒 Security notes

None.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions