-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
test: add test case for useSpeech #388
Conversation
--- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/ant-design/x?shareId=XXXX-XXXX-XXXX-XXXX).
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. 🔧 ast-grep (0.31.1)components/sender/__tests__/index.test.tsxAn unexpected error occurred while running ast-grep. 📝 Walkthrough概述演练该拉取请求为 变更
诗歌
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 (
|
WalkthroughThis pull request adds new test cases for the Changes
|
Bundle ReportBundle size has no change ✅ |
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: 1
🧹 Nitpick comments (2)
components/sender/__tests__/index.test.tsx (2)
142-170
: 测试用例结构清晰,但建议增加更多场景测试测试套件结构合理,覆盖了基本的功能点。但建议考虑添加以下测试场景:
- allowSpeech 为 false 时的情况
- 录音状态变化时的 UI 反馈
- 错误处理场景
149-162
: 建议补充自定义配置的边界测试当前测试验证了 recording 状态变化的回调,但建议增加以下测试:
- recording 初始值为 true 的情况
- 连续切换 recording 状态的场景
it('speech button functionality', () => { | ||
const { container } = render(<Sender allowSpeech />); | ||
const speechButton = container.querySelector('.ant-sender-actions-btn'); | ||
fireEvent.click(speechButton!); | ||
expect(container.querySelector('.ant-sender-actions-btn')).toBeInTheDocument(); | ||
}); |
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.
🛠️ Refactor suggestion
建议增强 speech button 功能测试的有效性
当前测试用例仅验证了按钮点击后仍然存在,这个断言的测试价值较低。建议改进测试用例:
it('speech button functionality', () => {
- const { container } = render(<Sender allowSpeech />);
+ const { container } = render(
+ <Sender
+ allowSpeech={{
+ recording: false,
+ }}
+ />,
+ );
const speechButton = container.querySelector('.ant-sender-actions-btn');
+ expect(speechButton).toHaveAttribute('aria-label', '开始录音');
fireEvent.click(speechButton!);
- expect(container.querySelector('.ant-sender-actions-btn')).toBeInTheDocument();
+ expect(speechButton).toHaveClass('ant-sender-actions-btn-recording');
+ expect(speechButton).toHaveAttribute('aria-label', '停止录音');
});
📝 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.
it('speech button functionality', () => { | |
const { container } = render(<Sender allowSpeech />); | |
const speechButton = container.querySelector('.ant-sender-actions-btn'); | |
fireEvent.click(speechButton!); | |
expect(container.querySelector('.ant-sender-actions-btn')).toBeInTheDocument(); | |
}); | |
it('speech button functionality', () => { | |
const { container } = render( | |
<Sender | |
allowSpeech={{ | |
recording: false, | |
}} | |
/>, | |
); | |
const speechButton = container.querySelector('.ant-sender-actions-btn'); | |
expect(speechButton).toHaveAttribute('aria-label', '开始录音'); | |
fireEvent.click(speechButton!); | |
expect(speechButton).toHaveClass('ant-sender-actions-btn-recording'); | |
expect(speechButton).toHaveAttribute('aria-label', '停止录音'); | |
}); |
size-limit report 📦
|
For more details, open the Copilot Workspace session.
Summary by CodeRabbit
新功能
Sender
组件添加了语音输入功能的测试套件。测试
allowSpeech
属性的功能,包括语音按钮的渲染、语音输入的行为以及按钮的存在性。