Skip to content

Conversation

@wooktori
Copy link
Contributor

@wooktori wooktori commented Dec 19, 2025

📝 변경 사항

  • 팔로우 컴포넌트 테스트 코드 작성했습니다.

테스트 코드 주요 패턴 설명 (useAddFollowers mock)

1. 커스텀 훅 mock 처리

jest.mock('@/hooks/use-follower', () => ({
  useAddFollowers: jest.fn(),
}));

2. 테스트 공통 초기화

beforeEach(() => {
  jest.clearAllMocks();

  (useAddFollowers as jest.Mock).mockReturnValue({
    mutate: jest.fn(),
  });
});

3. 성공 케이스 테스트 패턴

test('팔로우 추가 성공 테스트', async () => {
  (useAddFollowers as jest.Mock).mockReturnValue({
    mutate: jest.fn((_data, options) => {
      options?.onSuccess?.();
    }),
  });
});

🔗 관련 이슈

Closes #201


🧪 테스트 방법

  • 수동 테스트 검증(로컬 환경)
  • 유닛 테스트 검증
  • 통합 테스트 검증

📸 스크린샷 (선택)

image

📋 체크리스트

  • 관련 문서를 업데이트했습니다 (필요한 경우)
  • 테스트를 추가/수정했습니다 (필요한 경우)
  • Breaking change가 있다면 명시했습니다

💬 추가 코멘트


CodeRabbit Review는 자동으로 실행되지 않습니다.

Review를 실행하려면 comment에 아래와 같이 작성해주세요

@coderabbitai review

Summary by CodeRabbit

테스트

  • Tests
    • 팔로우 관련 컴포넌트의 단위 테스트 추가
    • 메시지 검색 기능의 테스트 커버리지 및 안정성 개선

✏️ Tip: You can customize this high-level summary in your review settings.

@wooktori wooktori self-assigned this Dec 19, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 19, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

안내

팔로잉 페이지 관련 컴포넌트의 단위 테스트 코드를 추가하는 변경사항입니다. FollowingNone 컴포넌트의 기본 렌더링 테스트와 message-following-search 컴포넌트의 포괄적인 테스트 스위트가 추가되었습니다.

변경사항

집단 / 파일 변경 요약
팔로잉 페이지 테스트
src/components/pages/message/message-following-none/index.test.tsx
FollowingNone 컴포넌트의 단위 테스트 파일 추가. 컴포넌트 렌더링 후 "아직 팔로우 한 사람이 없어요." 텍스트 존재 여부를 검증합니다.
팔로우 검색 페이지 테스트
src/components/pages/message/message-following-search/index.test.tsx
message-following-search 컴포넌트의 종합 테스트 스위트 추가. renderForm 헬퍼 함수와 공유 queryClient 도입, useAddFollowers 훅 모킹, 빈 닉네임 입력 오류, 성공적 팔로우 추가, 사용자 미존재 오류, 모달 취소, 오류 메시지 초기화, Enter 키 동작 등 다양한 시나리오를 테스트합니다.

코드 리뷰 예상 난이도

🎯 3 (중간) | ⏱️ ~20분

  • 주의할 점:
    • message-following-search 테스트의 renderForm 헬퍼 함수와 queryClient 생명주기 관리 로직 검증
    • useAddFollowers 훅 모킹 설정이 모든 테스트 케이스에서 올바르게 동작하는지 확인
    • 각 테스트 케이스의 비동기 대기 로직(waitFor) 타이밍이 적절한지 검토

추천 레이블

Ready For Review!

추천 리뷰어

  • yoorli

🐰 테스트 코드 쓰는 날은 반짝반짝,
팔로잉 페이지 검증하고 또 검증해,
모든 경우를 다 잡아내니,
버그는 어디 숨었나 놀라고 달아나!
테스트가 튼튼하면 맘도 편하지~ ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 팔로우 컴포넌트 테스트 코드 작성이라는 주요 변경사항을 명확하게 설명하고 있으며, 실제 변경 내용과 일치합니다.
Description check ✅ Passed PR 설명은 필수 템플릿 섹션을 포함하고 있으며, 변경사항, 관련 이슈, 테스트 방법, 체크리스트 등이 모두 작성되어 있습니다.
Linked Issues check ✅ Passed PR은 관련 이슈 #201의 팔로잉 페이지 테스트 코드 작성 요구사항을 충족하며, 두 개의 테스트 파일 추가로 테스트 커버리지를 향상시키고 있습니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 팔로우 컴포넌트의 테스트 코드 작성이라는 명시된 목표에 부합하며, 범위를 벗어난 변경은 없습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot requested a review from yoorli December 19, 2025 13:09
@github-actions
Copy link

github-actions bot commented Dec 19, 2025

🎭 Playwright Report

E2E Test가 성공적으로 완료되었습니다.

Test 요약 내용을 확인해주세요.

Status Build Log Updated (UTC)
✅ Ready View Build 2025-12-23 00:03:51

📊 Test Summary

  • ✅ Passed: 3
  • ❌ Failed: 0
  • ⏱️ Duration: 28.8s

📜 Test Details

✅ Passed Tests (3)
  • profile.test.ts (3)
    • [chromium] 존재하지 않는 프로필 페이지로 접속 시 404 redirect 되는 지 테스트
    • [firefox] 존재하지 않는 프로필 페이지로 접속 시 404 redirect 되는 지 테스트
    • [webkit] 존재하지 않는 프로필 페이지로 접속 시 404 redirect 되는 지 테스트

@github-actions
Copy link

github-actions bot commented Dec 19, 2025

🚀 PR Preview Report

Build가 성공적으로 완료되었습니다.

Preview에서 변경사항을 확인하세요.

Status Preview Build Log Updated (UTC)
✅ Ready Visit Preview View Logs 2025-12-23 00:03:51

@github-actions
Copy link

github-actions bot commented Dec 19, 2025

🎨 Storybook Report

변경 사항이 없습니다

모든 Story가 이전 빌드와 동일합니다.

Status Storybook Build Log Updated (UTC)
✅ Unchanged View Storybook View Build 2025-12-23 00:04:15

@github-actions
Copy link

github-actions bot commented Dec 19, 2025

📊 Coverage Report

Status Build Log Updated (UTC)
✅ Ready View Build 2025-12-23 00:02:38

📈 #215main에 병합하면 coverage가 3.19% 증가합니다.

Coverage 요약

@@             Coverage Diff             @@
##             main     #215       +/-   ##
===========================================
+ Coverage   31.46%   34.65%    +3.19%     
===========================================
  Files         163      164        +1     
  Lines        7224     7238       +14     
  Branches      255      255         0     
===========================================
+ Hits         2273     2508      +235     
- Misses       4951     4730      -221     

영향받은 파일

파일 Coverage 변화
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/pages/message/index.ts 100.00% (+100.00%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/pages/message/chat/index.tsx 50.61% (+50.61%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/pages/message/message-following-modal/index.tsx 93.90% (+93.90%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/pages/message/message-following-none/index.tsx 100.00% (+100.00%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/pages/message/message-following-search/index.tsx 100.00% (+32.23%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/shared/index.ts 100.00% (+100.00%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/shared/animate-dynamic-height/index.tsx 31.42% (+31.42%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/shared/auth-switch-link/index.tsx 66.66% (+66.66%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/shared/error-message/index.tsx 100.00% (+100.00%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/shared/form-input/index.tsx 27.92% (+27.92%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/components/shared/search-bar/index.tsx 20.77% (+20.77%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/hooks/use-intersection-observer/index.ts 59.09% (+59.09%) ⬆️
/home/runner/work/WeGo_FrontEnd/WeGo_FrontEnd/src/lib/constants/group-list.ts 100.00% (+100.00%) ⬆️

Copy link
Member

@Chiman2937 Chiman2937 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다~~~

Copy link
Member

Choose a reason for hiding this comment

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

FollowingNone 컴포넌트 자체를 테스트하고 있는데, 크게 의미가 없어보여요

message/page.test.tsx로 이관 후, followers가 0명이면 message-following-none 컴포넌트가 보여지는지 테스트 하는게 더 좋을 것 같아요!

Copy link
Member

Choose a reason for hiding this comment

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

message-following-search 컴포넌트를 지금봤는데, 이 파일 내부에서 모달과 팔로우 추가 버튼 둘다 관리하고 있네용

  1. 모달을 별도 파일로 분리하기(message-following-modal ? )
  2. 모달 내부에서 input값을 현재 직접 state로 제어하는 방식 => tanstack form 관리 방식으로 수정
  3. errorMessage를 zod로 제어하기

프로젝트 통일성을 위해 이 정도로 수정되면 좋을 것 같습니다!

Comment on lines 9 to 11
jest.mock('@/hooks/use-follower', () => ({
useAddFollowers: jest.fn(),
}));
Copy link
Member

@Chiman2937 Chiman2937 Dec 20, 2025

Choose a reason for hiding this comment

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

test를 위해 별도의 queryclient를 만들었는데, react query mutation을 사용하는 useAddFollowers도 모킹을 하고 있네요!

사실 api/follower-service의 addFollower만 모킹을 해주면 useAddFollowers를 모킹할 필요가 없어요!

실제로 이렇게 하는게 더 좋은 이유가 테스트 코드 작성 시 실제 동작과 최대한 가깝게 테스트를 해야하기 때문이에요.

// as-is
message-following-search => useAddFollowers(모킹)
// to-be
message-following-search => useAddFollowers => addFollowers(모킹)

이렇게 하면 react query의 내부 상태를 전부 정상적으로 사용할 수 있고, 테스트 코드를 더 유연하게 작성할 수 있을 것으로 보이네요!

app/(user)/profile/[userId]/page.test.tsx를 확인해보시면 api 호출 함수만 모킹해놓고, page가 알아서 동작하게 만든 다음 테스트를 진행하도록 작성했는데, 여기 구문 참고해보시면 좋을 것 같네요 :)

@claudia99503
Copy link
Member

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (2)
src/components/pages/message/message-following-none/index.test.tsx (1)

5-10: 상위 페이지 테스트로 통합을 권장합니다.

FollowingNone 컴포넌트를 독립적으로 테스트하는 것보다, message/page.test.tsx에서 followers가 0명일 때 이 컴포넌트가 렌더링되는지 통합 테스트하는 것이 더 의미있는 테스트가 될 것입니다.

src/components/pages/message/message-following-search/index.test.tsx (1)

9-11: API 서비스 레벨에서 모킹하는 것을 권장합니다.

현재 useAddFollowers 훅을 모킹하고 있지만, 실제로는 api/follower-serviceaddFollower 함수만 모킹하는 것이 더 좋습니다. 이렇게 하면:

  • React Query의 내부 상태를 정상적으로 사용 가능
  • 실제 동작에 더 가까운 테스트 수행 가능
  • 테스트 코드의 유연성 향상

app/(user)/profile/[userId]/page.test.tsx를 참고하시면 API 호출 함수만 모킹하고 컴포넌트가 자연스럽게 동작하도록 작성된 예시를 확인할 수 있습니다.

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dcdf677 and 6754251.

📒 Files selected for processing (2)
  • src/components/pages/message/message-following-none/index.test.tsx (1 hunks)
  • src/components/pages/message/message-following-search/index.test.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-17T09:40:37.733Z
Learnt from: HopeFullee
Repo: WeGo-Together/WeGo_FrontEnd PR: 205
File: src/components/pages/post-meetup/fields/cap-field/index.tsx:47-47
Timestamp: 2025-12-17T09:40:37.733Z
Learning: In TanStack Form with Zod validation, when field.state.meta.isValid is false, field.state.meta.errors is guaranteed to have at least one entry. Therefore, in an isInvalid check defined as field.state.meta.isTouched && !field.state.meta.isValid, safely access field.state.meta.errors[0] without extra null/empty checks. This guideline applies to TSX form fields under src/components/pages (and similar forms using the same pattern).

Applied to files:

  • src/components/pages/message/message-following-none/index.test.tsx
  • src/components/pages/message/message-following-search/index.test.tsx

describe('Following None 컴포넌트 테스트', () => {
test('Following None 렌더링 테스트', () => {
render(<FollowingNone />);
expect(screen.getByText('아직 팔로우 한 사람이 없어요.'));
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

단언문(assertion)이 누락되어 테스트가 무의미합니다.

screen.getByText()만 호출하고 있으며 .toBeInTheDocument()와 같은 assertion 메서드가 없습니다. 이 상태에서는 요소가 존재하는지 검증하지 않습니다.

🔎 수정 제안
-    expect(screen.getByText('아직 팔로우 한 사람이 없어요.'));
+    expect(screen.getByText('아직 팔로우 한 사람이 없어요.')).toBeInTheDocument();
🤖 Prompt for AI Agents
In src/components/pages/message/message-following-none/index.test.tsx around
line 8, the test only calls screen.getByText('아직 팔로우 한 사람이 없어요.') without an
assertion, making the test ineffective; update the expectation to assert
presence (e.g., wrap the call with expect(...).toBeInTheDocument()) so the test
actually verifies the element exists, ensuring jest-dom matchers are available
or imported if needed.

fireEvent.click(screen.getByText('팔로우'));

// 에러 div 체크
expect(screen.getByText('존재하지 않는 유저입니다.'));
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

단언문(assertion)이 누락되어 테스트가 무의미합니다.

screen.getByText()만 호출하고 있으며 .toBeInTheDocument()와 같은 assertion 메서드가 없습니다. 이 상태에서는 에러 메시지가 존재하는지 제대로 검증하지 않습니다.

🔎 수정 제안
-    expect(screen.getByText('존재하지 않는 유저입니다.'));
+    expect(screen.getByText('존재하지 않는 유저입니다.')).toBeInTheDocument();
🤖 Prompt for AI Agents
In src/components/pages/message/message-following-search/index.test.tsx around
line 120, the test calls screen.getByText('존재하지 않는 유저입니다.') but lacks an
assertion so it doesn't actually verify presence; replace the bare call with an
assertion such as expect(screen.getByText('존재하지 않는 유저입니다.')).toBeInTheDocument()
(or .toBeVisible()) and ensure @testing-library/jest-dom is imported/configured
in the test setup so the matcher is available.


fireEvent.click(screen.getByText('팔로우'));

expect(screen.getByText('존재하지 않는 유저입니다.'));
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

단언문(assertion)이 누락되어 테스트가 무의미합니다.

screen.getByText()만 호출하고 있으며 .toBeInTheDocument()와 같은 assertion 메서드가 없습니다. 에러 메시지가 표시되는지 검증하려면 assertion을 추가해야 합니다.

🔎 수정 제안
-    expect(screen.getByText('존재하지 않는 유저입니다.'));
+    expect(screen.getByText('존재하지 않는 유저입니다.')).toBeInTheDocument();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(screen.getByText('존재하지 않는 유저입니다.'));
expect(screen.getByText('존재하지 않는 유저입니다.')).toBeInTheDocument();
🤖 Prompt for AI Agents
In src/components/pages/message/message-following-search/index.test.tsx around
line 156, the test calls screen.getByText('존재하지 않는 유저입니다.') but lacks an
assertion, so it doesn't actually verify the message is present; update the test
to assert the element is in the document (for example, wrap the getByText call
in an expect(...).toBeInTheDocument() or use a suitable jest-dom matcher) so the
test fails when the error message is not rendered.

Copy link
Member

@yoorli yoorli left a comment

Choose a reason for hiding this comment

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

수고하셨습니다

@wooktori wooktori force-pushed the hwanwook-feat/follow-test branch from 6754251 to 29446e3 Compare December 22, 2025 13:43
@wooktori wooktori merged commit eee109b into main Dec 23, 2025
7 checks passed
@wooktori wooktori deleted the hwanwook-feat/follow-test branch December 23, 2025 00:10
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.

[팔로잉 페이지] 테스트 코드 작성

5 participants