Skip to content

fix: 修复兑换码额度输入框删除全部数值时强制为显示为0的问题 - #6702

Closed
lihu-001 wants to merge 1 commit into
QuantumNous:mainfrom
lihu-001:fix/duihuanm_del
Closed

fix: 修复兑换码额度输入框删除全部数值时强制为显示为0的问题#6702
lihu-001 wants to merge 1 commit into
QuantumNous:mainfrom
lihu-001:fix/duihuanm_del

Conversation

@lihu-001

@lihu-001 lihu-001 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • fix: 修复兑换码额度输入框删除全部数值时强制为显示为0的问题

📝 变更描述 / Description

  • 调整 web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx:300
  • 输入框为空时保留空字符串,不再通过 || 0 强制转换为 0
  • 非空输入仍正常转换为数字
  • 新增回归测试,覆盖:
    • 新增兑换码时清空额度
    • 修改兑换码时清空额度

🚀 变更类型 / Type of change

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

image

Summary by CodeRabbit

  • Bug Fixes

    • Fixed redemption quota inputs so they can be cleared without automatically reverting to zero.
    • Preserved decimal quota values when entered.
  • Tests

    • Added coverage for clearing quota values in both new redemption and update workflows.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The redemption quota input now preserves an empty value instead of forcing 0. Tests cover clearing the quota in create and update drawer modes.

Changes

Redemption quota clearing

Layer / File(s) Summary
Preserve empty quota values
web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx
The quota input retains '' when cleared and parses non-empty input as a floating-point number.
Validate quota clearing
web/src/features/redemption-codes/components/__tests__/quota-input.test.tsx
The test suite renders create and update drawers, simulates input changes, waits for update data, and verifies that the quota can be cleared. It also cleans up React, DOM, API, and browser state.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

I tap my paws; the field is clear,
No stubborn zero lingers here.
Create or update, both agree,
An empty quota stays empty.
— A pleased little rabbit 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the fix for the redemption-code quota input displaying 0 after all values are deleted.
Linked Issues check ✅ Passed The change preserves an empty string and adds create and update regression tests, meeting issue #6681 requirements.
Out of Scope Changes check ✅ Passed The changes are limited to the quota input behavior and related regression tests.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between e926e5c and 62852cb.

📒 Files selected for processing (2)
  • web/src/features/redemption-codes/components/__tests__/quota-input.test.tsx
  • web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx

Comment on lines +127 to +150
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
)
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 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

@lihu-001 lihu-001 closed this Aug 7, 2026
@Calcium-Ion

Copy link
Copy Markdown
Member

您好,建议git提交账号使用github同账号

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

兑换码的新值与修改页面的额度输入框,有值时,点击键盘的backspace键,删除到最后会强制显示为0

3 participants