-
-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: onSearch be call onBlur #1085
base: master
Are you sure you want to change the base?
fix: onSearch be call onBlur #1085
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Walkthrough本次变更主要涉及 Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
tests/Select.test.tsxOops! Something went wrong! :( ESLint: 8.57.1 Error: Cannot read config file: /.eslintrc.js
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
tests/BaseSelect.test.tsx (1)
128-149
: 建议完善测试用例的覆盖范围当前测试用例存在以下需要改进的地方:
- 测试名称应该反映
showSearch={true}
的设置- 缺少对初始
searchValue="1"
的验证- 建议添加
showSearch={false}
的场景测试建议修改如下:
- it('mode with null, onContainerBlur params is blur', () => { + it('mode为null且showSearch为true时,onContainerBlur触发onSearch', () => { const onSearch = jest.fn(); const { container } = render( // ... existing code ... ); + // 验证初始值 + expect(container.querySelector('input').value).toBe('1'); // ... remaining code ... }); + it('mode为null且showSearch为false时,onContainerBlur不触发onSearch', () => { + // 添加showSearch=false的测试用例 + });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
src/BaseSelect/index.tsx
(1 hunks)tests/BaseSelect.test.tsx
(1 hunks)tests/Select.test.tsx
(1 hunks)
🔇 Additional comments (3)
tests/BaseSelect.test.tsx (2)
127-127
: 测试结构清晰明确!
测试套件的命名准确反映了其测试目的,结构符合最佳实践。
127-174
: 建议增加测试用例以确保完整的行为覆盖
当前的测试用例集没有完全覆盖PR的目标场景。为确保修复的完整性,建议添加以下测试场景:
- 单选模式下的行为测试,以便与多选模式进行对比
- 验证重新获得焦点时是否会触发新的搜索请求
- 测试空值和特殊字符的搜索行为
src/BaseSelect/index.tsx (1)
438-438
: 搜索事件源的逻辑修改看起来符合预期
这个改动通过在 mergedShowSearch
为 true 时将搜索事件源从 'typing' 或 'effect' 更改为 'blur',解决了重新获得焦点时不必要的建议请求问题。这与 PR 的目标一致。
运行以下脚本验证此更改是否正确处理了所有搜索事件源:
✅ Verification successful
Let me gather more context about the search event handling to ensure a comprehensive verification.
Let me try one more verification to check the component's search-related logic:
让我检查一下相关的测试文件以确保这个改动的行为是否符合预期:
搜索事件源的修改已得到验证,实现符合预期
根据代码分析和测试用例验证,这个改动是正确的:
- 在输入时触发
source: 'typing'
- 在失焦时触发
source: 'blur'
- 在其他情况下触发
source: 'effect'
或source: 'submit'
这个修改完全符合 PR 的目标,能够正确处理重新获得焦点时的搜索行为,避免不必要的建议请求。测试用例也验证了这些行为。
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# 检查代码库中是否存在其他使用 onSearch 的地方
ast-grep --pattern 'onSearch($_, { source: $_ })'
Length of output: 571
Script:
#!/bin/bash
# 检查 onSearch 的定义和类型
ast-grep --pattern 'onSearch?: $_'
# 检查相关的测试用例
rg "onSearch.*source" -A 3 -B 3 "test|spec|__tests__"
Length of output: 152
Script:
#!/bin/bash
# 检查组件中与搜索相关的状态和处理逻辑
rg "onSearch|showSearch|searchValue" -A 2 -B 2 src/BaseSelect/index.tsx
# 查找测试文件
fd "test|spec" -e tsx -e ts
Length of output: 3571
Script:
#!/bin/bash
# 检查测试文件中与搜索事件源相关的测试用例
rg "onSearch.*source|showSearch.*blur" -A 3 -B 3 tests/
# 特别关注与 blur 事件相关的测试
rg "test.*blur" -A 5 -B 2 tests/
Length of output: 1397
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1085 +/- ##
==========================================
+ Coverage 98.24% 98.38% +0.13%
==========================================
Files 39 39
Lines 1483 1483
Branches 441 447 +6
==========================================
+ Hits 1457 1459 +2
+ Misses 26 24 -2 ☔ View full report in Codecov by Sentry. |
fix ant-design/ant-design#50642
Summary by CodeRabbit
新功能
BaseSelect
组件的搜索功能和下拉菜单可见性,提供更直观的用户体验。测试
BaseSelect
组件新增了测试用例,增强了对搜索输入和焦点事件的覆盖。Select
组件的测试,确保其在各种场景下的功能和行为正常,包括下拉菜单的打开和关闭、焦点和失去焦点事件的处理。