Skip to content

test(hooks): useExpandableText, useScrollFloatingVisibility, useScrollOnNextQueryChange 테스트#354

Merged
jay0425 merged 5 commits into
developfrom
#347-test-hooks
May 5, 2026
Merged

test(hooks): useExpandableText, useScrollFloatingVisibility, useScrollOnNextQueryChange 테스트#354
jay0425 merged 5 commits into
developfrom
#347-test-hooks

Conversation

@jay0425
Copy link
Copy Markdown
Collaborator

@jay0425 jay0425 commented May 1, 2026

🛠️ 설명 (Description)

공통 훅 3종에 대한 테스트 코드를 추가했습니다.

  • useExpandableText
  • useScrollFloatingVisibility
  • useScrollOnNextQueryChange

각 훅의 상태 변화와 부수효과가 의도대로 동작하는지 검증하는
회귀 테스트를 작성했습니다.

📝 변경 사항 요약 (Summary)

  • useExpandableText 테스트 파일 추가
  • useScrollFloatingVisibility 테스트 파일 추가
  • useScrollOnNextQueryChange 테스트 파일 추가
  • ResizeObserver, scrollIntoView, requestAnimationFrame,
    이벤트 리스너 cleanup 동작 검증 추가

💁 변경 사항 이유 (Why)

  • 훅의 핵심 분기 로직을 명확하게 보호하기 위해 테스트를 추가했습니다.
  • DOM 크기 변화, 스크롤 방향, 쿼리 변경처럼 회귀가 발생하기 쉬운
    동작을 안정적으로 검증하기 위해서입니다.
  • observer, event listener, animation frame 정리 누락 같은
    부수효과 관련 버그를 사전에 방지하기 위해서입니다.

✅ 테스트 계획 (Test Plan)

  • 유닛 테스트 대상
  • hooks/useExpandableText.test.ts
  • hooks/useScrollFloatingVisibility.test.ts
  • hooks/useScrollOnNextQueryChange.test.ts

검증 항목:

  • useExpandableText
    • scrollHeight > clientHeight + 1 기준 overflow 판별
    • toggleExpanded 호출 시 isExpanded 토글
    • 접힘 상태에서만 ResizeObserver 재계산 수행
    • 언마운트 시 disconnect 호출
  • useScrollFloatingVisibility
    • threshold 초기 상태 검증
    • threshold 이전 구간에서 항상 노출되는지 검증
    • threshold 통과 후 스크롤 방향과 delta에 따른 노출 상태 검증
    • triggerRef, targetRef, resize, cleanup 분기 검증
  • useScrollOnNextQueryChange
    • 최초 마운트 시 스크롤 미발생 검증
    • markWillChange 없이 query 변경 시 스크롤 미발생 검증
    • markWillChange 이후 1회만 scrollIntoView 호출되는지 검증
    • behaviorblock: "start" 옵션 전달 검증

실행 명령어:

pnpm test -- hooks/useExpandableText.test.ts hooks/useScrollFloatingVisibility.test.ts hooks/useScrollOnNextQueryChange.test.ts

🔗 관련 이슈 (Related Issues)

☑️ 체크리스트 (Checklist)

  • 코드가 프로젝트 코딩 컨벤션을 따릅니다.
  • 테스트 코드가 작성되었고, 통과했습니다.
  • 변경 사항에 대한 문서화가 완료되었습니다.
  • 필요한 경우, 다른 팀원에게 리뷰를 요청했습니다.
  • CI/CD 파이프라인이 성공했습니다.

👀 리뷰어를 위한 참고 사항 (Notes for Reviewers)

➕ 추가 정보 (Additional Information)

jay0425 added 2 commits May 1, 2026 21:05
- useExpandableText, useScrollFloatingVisibility, useScrollOnNextQueryChange 테스트를 추가

Resolves: #347
- React 19에서 deprecated 된 MutableRefObject 사용을 제거하고,
테스트에서 ref.current를 직접 할당하는 의도를 명확히 하기 위해 WritableRef 타입으로 교체

Resolves: #347
@jay0425 jay0425 self-assigned this May 1, 2026
@jay0425 jay0425 added the test 테스트 코드 추가/수정 label May 1, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces unit tests for the useExpandableText, useScrollFloatingVisibility, and useScrollOnNextQueryChange hooks, covering functionalities such as overflow detection, scroll-based visibility, and query-triggered scrolling. The review feedback focuses on improving test isolation by ensuring that global objects and properties, specifically ResizeObserver and window.scrollY, are properly restored after being mocked or modified to prevent side effects in other test files.

Comment thread hooks/useExpandableText.test.ts
Comment thread hooks/useScrollFloatingVisibility.test.ts
jay0425 added 3 commits May 1, 2026 22:18
- useExpandableText 테스트에서 전역 ResizeObserver 원본을 저장하고 복구하도록 수정
- 테스트 간 전역 객체 변경 영향이 남지 않도록 처리

Resolves: #347
- useScrollFloatingVisibility 테스트에서 window scrollY/pageYOffset 원본 descriptor를 저장하고 복구하도록 수정
- Object.defineProperty로 변경한 전역 스크롤 값이 테스트 간에 남지 않도록 처리

Resolves: #347
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

🧷 Preview: https://reboot-n0mzvyzn2-code-base.vercel.app
⏰ 배포 시각: 2026년 05월 04일 21시 13분

@jay0425 jay0425 merged commit e66ae42 into develop May 5, 2026
1 check passed
@jay0425 jay0425 deleted the #347-test-hooks branch May 5, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test 테스트 코드 추가/수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TEST] 커스텀 훅 테스트 코드 작성

1 participant