fix: 修复兑换码额度输入框删除全部数值时强制为显示为0的问题 - #6702
Conversation
WalkthroughThe redemption quota input now preserves an empty value instead of forcing ChangesRedemption quota clearing
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@web/src/features/redemption-codes/components/__tests__/quota-input.test.tsx`:
- Around line 127-150: Update the quota test helpers getQuotaInput and
changeInput to use React Testing Library’s accessible-label query and user-event
interaction instead of manual DOM traversal, native value setters, and
dispatched events. Clear and set the quota input through the user-facing
interaction API while preserving the existing test behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6356fce4-e06e-45a1-a4be-4fa665778f3e
📒 Files selected for processing (2)
web/src/features/redemption-codes/components/__tests__/quota-input.test.tsxweb/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx
| function getQuotaInput(): HTMLInputElement { | ||
| const label = [...document.querySelectorAll<HTMLLabelElement>('label')].find( | ||
| (candidate) => candidate.textContent?.includes('Quota') | ||
| ) | ||
| assert.ok(label, 'Expected quota label') | ||
| const input = label | ||
| .closest('[data-slot="form-item"]') | ||
| ?.querySelector<HTMLInputElement>('input[type="number"]') | ||
| assert.ok(input, 'Expected quota input') | ||
| return input | ||
| } | ||
|
|
||
| async function changeInput(input: HTMLInputElement, value: string) { | ||
| await act(async () => { | ||
| const valueSetter = Object.getOwnPropertyDescriptor( | ||
| domWindow.HTMLInputElement.prototype, | ||
| 'value' | ||
| )?.set | ||
| assert.ok(valueSetter) | ||
| valueSetter.call(input, value) | ||
| input.dispatchEvent( | ||
| new domWindow.Event('input', { bubbles: true }) as unknown as Event | ||
| ) | ||
| }) |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Use React Testing Library for the quota interaction.
Replace manual DOM queries and direct value setter calls with React Testing Library queries and user-event clearing. Query the input by its accessible label. This keeps the regression test aligned with user behavior.
As per coding guidelines, “组件测试使用 React Testing Library,从用户视角查询元素并测试交互和行为”.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/features/redemption-codes/components/__tests__/quota-input.test.tsx`
around lines 127 - 150, Update the quota test helpers getQuotaInput and
changeInput to use React Testing Library’s accessible-label query and user-event
interaction instead of manual DOM traversal, native value setters, and
dispatched events. Clear and set the quota input through the user-facing
interaction API while preserving the existing test behavior.
Source: Coding guidelines
|
您好,建议git提交账号使用github同账号 |
Important
📝 变更描述 / Description
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit
Bug Fixes
Tests