Skip to content

[feature] 소개페이지 컴포넌트 테스트 코드 작성#448

Merged
seongwon030 merged 1 commit intodevelop-fefrom
feature/#447-introduce-page-test-FE-125
Jul 12, 2025
Merged

[feature] 소개페이지 컴포넌트 테스트 코드 작성#448
seongwon030 merged 1 commit intodevelop-fefrom
feature/#447-introduce-page-test-FE-125

Conversation

@seongwon030
Copy link
Member

@seongwon030 seongwon030 commented May 28, 2025

#️⃣연관된 이슈

ex) #447

📝작업 내용

  • 초기 로딩 상태에서 스피너 표시 여부 테스트
  • 이미지 로드 완료 후 UI 상태 변경 테스트
  • Header, Footer 컴포넌트 렌더링 테스트
  • 외부 컴포넌트(Header, Footer, Spinner) 모킹 설정

테스트 케이스

1. 초기 상태 테스트

  • 스피너가 표시되는지 확인
  • 이미지가 숨겨진 상태인지 확인

2. 이미지 로드 완료 테스트

  • 스피너가 사라지는지 확인
  • 이미지가 표시되는지 확인

3. 레이아웃 컴포넌트 테스트

  • Header 컴포넌트 렌더링 확인
  • Footer 컴포넌트 렌더링 확인

testing-library 메서드 정리

테스트의 필요성

오늘 태규님에게 테스트에 대한 얘기를 듣고 왔습니다! 단위 테스트든 UI테스트든 가장 중요한 건
1. 공통적으로 쓰이는 로직일 때
2. 내부 구현 로직이 복잡하거나 상태 변화가 많을 때

라고 하셨습니다. 1번은 여러 기능에 영향을 미치므로 이 로직이 망가지면 여러 손해가 발생할 수 있습니다.
2번은 에러를 던질 가능성이 많다는 것으로 해석할 수 있습니다.

도입했던 이유

저는 1. 커버리지 높이기, 2. react-testing-library공부를 목적으로 했는데,
1번은 단위 테스트에서 지양해야 할 점이라고 합니다.

유틸함수 테스트

단위테스트 중 유틸 함수는 util이라는 이름처럼 여러 곳에서 쓰이므로 적합합니다.
하지만 이전에 올렸던 stringToDate에 대한 단위 테스트(해당 pr)는, 테스트의 용이성을 위해 기존 함수를 분리했기에
테스트에 대한 의존성만 높아진 것입니다. 추가로 테스트가 필요한 점 2번 또한 간과한 것이 될 수 있겠네요.

UI 테스트

이것도 비즈니스 로직이 있다면 사용자 흐름을 테스트할 수 있어서 용이할 수 있습니다. 하지만 제가 올린 pr은
공통적으로 쓰이지도 않고 비즈니스적인 흐름도 없어, "굳이" 할 이유는 없던 것 같습니다.
혹여나 다른 로직이 추가되면 테스트를 바꾸는 데에도 리소스가 발생하기 때문이며, ci/cd에도 영향을 줄 수 있습니다.

결론

공부할 목적으로 하면 좋은 것 같습니다. 다만, 테스트를 한다고 무조건 좋은 것은 아니라는 것을 알게 되었습니다.
단위테스트와 커버리지에 대한 얘기가 부족했던 것 같아서 이 부분 꼭 같이 얘기해보는 게 좋을 것 같아요 ㅎㅎ

단위테스트 이 책도 추천해주셨습니다 ~

중점적으로 리뷰받고 싶은 부분(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

논의하고 싶은 부분(선택)

🫡 참고사항

Summary by CodeRabbit

  • Tests
    • IntroducePage 컴포넌트에 대한 새로운 테스트가 추가되어, 로딩 스피너와 이미지 표시, Header 및 Footer 렌더링이 올바르게 동작하는지 검증합니다.

- 초기 로딩 상태에서 스피너 표시 테스트
- 이미지 로드 완료 후 UI 상태 변경 테스트
- Header, Footer 컴포넌트 렌더링 테스트
- 외부 컴포넌트 모킹 설정
@seongwon030 seongwon030 requested a review from oesnuj May 28, 2025 15:05
@seongwon030 seongwon030 self-assigned this May 28, 2025
@seongwon030 seongwon030 added ✅ Test test 관련(storybook, jest...) 💻 FE Frontend labels May 28, 2025
@netlify
Copy link

netlify bot commented May 28, 2025

Deploy Preview for moadong ready!

Name Link
🔨 Latest commit 9b6ad29
🔍 Latest deploy log https://app.netlify.com/projects/moadong/deploys/6837264680379e000858d439
😎 Deploy Preview https://deploy-preview-448--moadong.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 39
Accessibility: 87
Best Practices: 92
SEO: 92
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 28, 2025

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Invalid regex pattern for base branch. Received: "**" at "reviews.auto_review.base_branches[0]"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

IntroducePage 컴포넌트에 대한 새로운 테스트 파일이 추가되었습니다. 이 테스트는 React Testing Library와 Jest를 사용하여 Spinner, Header, Footer 컴포넌트 및 이미지 에셋을 모킹하고, 컴포넌트의 렌더링 및 이미지 로딩 동작을 검증합니다.

Changes

파일/경로 변경 요약
frontend/src/pages/IntroducePage/IntroducePage.test.tsx IntroducePage 컴포넌트 테스트 파일 신규 추가, Spinner, Header, Footer, 이미지 에셋 모킹 및 렌더링/동작 테스트 구현

Assessment against linked issues

Objective Addressed Explanation
IntroducePage 컴포넌트 테스트 코드 작성 (FE-125)

Possibly related PRs

Suggested reviewers

  • oesnuj
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented May 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

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: 0

🧹 Nitpick comments (1)
frontend/src/pages/IntroducePage/IntroducePage.test.tsx (1)

22-48: 테스트 커버리지 개선을 위한 추가 제안

현재 테스트는 핵심 기능을 잘 다루고 있습니다. 다음과 같은 추가 테스트를 고려해볼 수 있습니다:

  1. 이미지 로딩 실패 시나리오 테스트
  2. 접근성 속성 확인 (aria-label, alt 텍스트 등)
  3. 여러 번의 로딩 상태 변경 테스트

예시 추가 테스트:

it('이미지 로딩 실패 시에도 적절하게 처리된다', () => {
  render(<IntroducePage />);
  
  const image = screen.getByAltText('소개 이미지');
  fireEvent.error(image);
  
  // 에러 처리 로직 검증
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1698da and 9b6ad29.

📒 Files selected for processing (1)
  • frontend/src/pages/IntroducePage/IntroducePage.test.tsx (1 hunks)
🔇 Additional comments (5)
frontend/src/pages/IntroducePage/IntroducePage.test.tsx (5)

1-3: 올바른 테스팅 라이브러리 import 구성

React Testing Library의 필수 유틸리티들이 적절하게 import되어 있습니다.


5-20: 잘 구조화된 컴포넌트 및 에셋 모킹

외부 의존성들이 일관된 패턴으로 모킹되어 있어 테스트 격리가 잘 되어 있습니다. data-testid를 사용한 접근 방식도 적절합니다.


23-30: 초기 상태 테스트 로직이 정확함

스피너의 표시와 이미지의 숨김 상태를 적절하게 검증하고 있습니다. getByTestIdgetByAltText 쿼리 사용이 적절합니다.


32-40: 이미지 로딩 완료 시나리오를 잘 테스트함

fireEvent.load를 사용한 이미지 로딩 시뮬레이션과 상태 변화 검증이 적절합니다. queryByTestId를 사용해 요소의 부재를 확인하는 것도 정확합니다.


42-47: 레이아웃 컴포넌트 렌더링 테스트가 적절함

Header와 Footer 컴포넌트의 렌더링을 간단하고 효과적으로 검증하고 있습니다.

Copy link
Member

@oesnuj oesnuj left a comment

Choose a reason for hiding this comment

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

PR 잘 읽었습니다!
결국 중요한 건 가치 있는 테스트를 작성하는 거지 커버리지를 100% 채우는 게 정답은 아니군요 ㅎㅎ
저도 단위테스트 책 한번 읽어보겠습니다 😎

@seongwon030 seongwon030 merged commit c23dbe5 into develop-fe Jul 12, 2025
8 checks passed
@seongwon030 seongwon030 deleted the feature/#447-introduce-page-test-FE-125 branch July 12, 2025 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💻 FE Frontend ✅ Test test 관련(storybook, jest...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] FE-125 소개페이지 컴포넌트 테스트 코드 작성

2 participants

Comments