Skip to content

Comments

[feature] debounce 유틸함수 단위 테스트 추가#444

Merged
seongwon030 merged 2 commits intodevelop-fefrom
feat/#443-test-debounce-function-FE-124
Jul 7, 2025
Merged

[feature] debounce 유틸함수 단위 테스트 추가#444
seongwon030 merged 2 commits intodevelop-fefrom
feat/#443-test-debounce-function-FE-124

Conversation

@seongwon030
Copy link
Member

@seongwon030 seongwon030 commented May 26, 2025

#️⃣연관된 이슈

ex) #443

📝작업 내용

Jest Mock 타이머 적용하기
Timer Mocks 를 참고하였습니다.

  • 연속된 함수 호출을 제어하는 debounce 유틸리티 함수에 대한 단위 테스트를 추가했습니다.
  • 지정된 시간(delay) 동안 마지막 호출만 실행되도록 하였습니다.
  • 함수 인자 전달 기능을 지원합니다.
  • 테스트 시 타이머가 자동 리셋됩니다.

테스트

  • 지정된 시간 후 함수가 한 번만 호출되는지 검증
  • 타이머 리셋 기능 검증
  • 함수 인자 전달 검증

사용 예시

const debouncedFn = debounce((value: string) => {
  console.log(value);
}, 1000);

// 연속 호출 시 마지막 호출만 실행됨
debouncedFn('test1');
debouncedFn('test2');
debouncedFn('test3');
// 1초 후 'test3'만 출력

그 외 작업

  • nvmrc추가 (22.12.0)

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

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

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

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

논의하고 싶은 부분이 있다면 작성해주세요.

🫡 참고사항

Summary by CodeRabbit

  • 테스트
    • debounce 유틸리티 함수에 대한 새로운 테스트가 추가되었습니다.
    • 함수 호출 시 지연 동작과 인자 전달이 올바르게 동작하는지 검증합니다.
  • 기타
    • 프로젝트 환경에서 사용할 Node.js 버전이 명시된 .nvmrc 파일이 추가되었습니다.

- 연속된 함수 호출을 제어하는 debounce 함수 구현
- 지정된 시간(delay) 동안 마지막 호출만 실행되도록 처리
- 함수 인자 전달 기능 지원
- 타이머 자동 리셋 기능 구현
@seongwon030 seongwon030 requested a review from oesnuj May 26, 2025 05:06
@seongwon030 seongwon030 self-assigned this May 26, 2025
@seongwon030 seongwon030 added ✅ Test test 관련(storybook, jest...) 💻 FE Frontend labels May 26, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 26, 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

debounce 유틸리티 함수에 대한 새로운 단위 테스트 파일이 추가되었습니다. Jest의 fake timer를 활용하여 debounce 동작, 인자 전달, 타이머 리셋 등 다양한 시나리오를 검증합니다. 또한, frontend 디렉토리에 Node.js 버전 22.12.0을 명시하는 .nvmrc 파일이 추가되었습니다.

Changes

파일/경로 변경 요약
frontend/src/utils/debounce.test.ts debounce 함수에 대한 Jest 기반 단위 테스트 추가
frontend/.nvmrc Node.js 버전 22.12.0 명시를 위한 .nvmrc 파일 추가

Assessment against linked issues

Objective Addressed Explanation
debounce 유틸함수 단위 테스트 추가 (FE-124)

Possibly related issues


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 13bf54e and dde050e.

📒 Files selected for processing (1)
  • frontend/.nvmrc (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/.nvmrc

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.

@seongwon030 seongwon030 linked an issue May 26, 2025 that may be closed by this pull request
3 tasks
@netlify
Copy link

netlify bot commented May 26, 2025

Deploy Preview for moadong ready!

Name Link
🔨 Latest commit dde050e
🔍 Latest deploy log https://app.netlify.com/projects/moadong/deploys/6835b0bf07c7ef00081643ce
😎 Deploy Preview https://deploy-preview-444--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: 37
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.

@codecov
Copy link

codecov bot commented May 26, 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 (2)
frontend/src/utils/debounce.test.ts (2)

1-6: 변수명 컨벤션 개선

변수명 mockfn을 camelCase 규칙에 맞게 mockFn으로 변경하는 것을 권장합니다.

-  let mockfn: jest.Mock;
+  let mockFn: jest.Mock;

44-49: 인자 전달 테스트가 올바름

debounced 함수에 전달된 인자가 원본 함수에 올바르게 전달되는지 정확하게 테스트하고 있습니다.

더 포괄적인 테스트 커버리지를 위해 다음과 같은 추가 테스트 케이스를 고려해볼 수 있습니다:

it('debounce 지연 시간이 0일 때 즉시 실행된다.', () => {
  const immediateDebouncedFn = debounce(mockFn, 0);
  immediateDebouncedFn();
  jest.advanceTimersByTime(0);
  expect(mockFn).toHaveBeenCalledTimes(1);
});

it('여러 번 호출 시 마지막 호출의 인자만 전달된다.', () => {
  debouncedFn('first');
  debouncedFn('second');
  debouncedFn('third');
  jest.advanceTimersByTime(1000);
  expect(mockFn).toHaveBeenCalledWith('third');
});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 52bc0a2 and 13bf54e.

📒 Files selected for processing (1)
  • frontend/src/utils/debounce.test.ts (1 hunks)
🔇 Additional comments (4)
frontend/src/utils/debounce.test.ts (4)

7-11: 테스트 설정이 올바르게 구현됨

Jest fake timers를 사용한 테스트 설정이 적절하며, mock 함수와 debounced 함수의 초기화가 올바르게 되어 있습니다.


13-16: 테스트 정리가 올바르게 구현됨

테스트 간 독립성을 보장하기 위한 timer 정리가 올바르게 구현되어 있습니다.


18-28: 기본 debounce 동작 테스트가 정확함

여러 번의 연속 호출 후 지정된 시간이 지나면 한 번만 실행되는 debounce의 핵심 기능을 정확하게 테스트하고 있습니다.


30-42: 타이머 리셋 기능 테스트가 정확함

debounce 함수의 타이머 리셋 기능을 정확하게 테스트하고 있습니다. 지정된 시간 내에 다시 호출되면 타이머가 리셋되어 원래 함수의 실행이 지연되는 동작을 올바르게 검증합니다.

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.

LGTM
테스트 코드 야무지네요 👍

@seongwon030 seongwon030 merged commit 23118e9 into develop-fe Jul 7, 2025
8 checks passed
@seongwon030 seongwon030 deleted the feat/#443-test-debounce-function-FE-124 branch July 7, 2025 13:25
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.

[feat] FE-124 debounce 유틸함수 단위 테스트 추가

2 participants