Browse Source

添加取消原因对话框选中状态测试

- 添加测试验证预定义原因点击后的选中状态样式
- 添加测试验证自定义原因输入时预定义原因选中状态被清除
- 验证选中状态切换和样式应用正确

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 3 tuần trước cách đây
mục cha
commit
b9b5d7f9bd

+ 44 - 0
mini/tests/unit/components/common/CancelReasonDialog.test.tsx

@@ -53,6 +53,50 @@ describe('CancelReasonDialog', () => {
     expect(defaultProps.onConfirm).toHaveBeenCalledWith(reason)
   })
 
+  it('应该显示选中状态当点击预定义原因时', () => {
+    const { getByTestId } = render(<CancelReasonDialog {...defaultProps} />)
+
+    // 点击第一个原因
+    const firstReason = getByTestId('cancel-reason-我不想买了')
+    fireEvent.click(firstReason)
+
+    // 验证选中状态样式
+    expect(firstReason).toHaveClass('border-primary')
+    expect(firstReason).toHaveClass('bg-primary/10')
+
+    // 点击第二个原因,第一个应该取消选中
+    const secondReason = getByTestId('cancel-reason-信息填写错误,重新下单')
+    fireEvent.click(secondReason)
+
+    // 第一个原因应该不再有选中状态
+    expect(firstReason).not.toHaveClass('border-primary')
+    expect(firstReason).not.toHaveClass('bg-primary/10')
+
+    // 第二个原因应该有选中状态
+    expect(secondReason).toHaveClass('border-primary')
+    expect(secondReason).toHaveClass('bg-primary/10')
+  })
+
+  it('应该清除预定义原因选中状态当输入自定义原因时', () => {
+    const { getByTestId, getByPlaceholderText } = render(<CancelReasonDialog {...defaultProps} />)
+
+    // 先点击一个预定义原因
+    const reasonOption = getByTestId('cancel-reason-我不想买了')
+    fireEvent.click(reasonOption)
+
+    // 验证有选中状态
+    expect(reasonOption).toHaveClass('border-primary')
+    expect(reasonOption).toHaveClass('bg-primary/10')
+
+    // 输入自定义原因
+    const input = getByPlaceholderText('请输入其他取消原因...')
+    fireEvent.input(input, { target: { value: '自定义取消原因' } })
+
+    // 预定义原因的选中状态应该被清除
+    expect(reasonOption).not.toHaveClass('border-primary')
+    expect(reasonOption).not.toHaveClass('bg-primary/10')
+  })
+
   it('应该调用onConfirm当确认按钮被点击时', () => {
     const { getByTestId } = render(<CancelReasonDialog {...defaultProps} />)