Archived (Split)
说明: 本故事的工作已拆分为以下三个独立故事:
原故事中的任务已完成部分保留作为历史记录,剩余工作由新故事继续完成。
As a 开发人员, I want 修复父子商品管理界面的测试用例,使其符合API模拟规范, so that 所有测试都能通过,为后续开发提供可靠测试保障
rpcClient模拟,而不是分别模拟各个客户端管理器[x] 分析当前测试失败的根本原因 (AC: 1, 2, 3, 8)
[x] 更新GoodsParentChildPanel测试文件以符合API模拟规范 (AC: 1, 4, 5, 6, 7)
docs/architecture/testing-strategy.md#API模拟规范更新模拟策略getAllByText变体createMockResponse辅助函数)[x] 更新ChildGoodsList测试文件以符合API模拟规范 (AC: 2, 4, 5, 7)
rpcClient模拟)rpcClient模拟,移除直接模拟goodsClientManager的代码[x] 更新BatchSpecCreatorInline测试文件以符合API模拟规范 (AC: 3, 4, 5, 7)
rpcClient模拟,移除直接模拟goodsClientManager的代码(不适用)[ ] 修复其他相关测试文件 (AC: 4, 5, 7)
BatchSpecCreator.test.tsx以符合API模拟规范goods-management.integration.test.tsx集成测试以符合API模拟规范[ ] 验证和调试测试修复 (AC: 1, 2, 3, 4, 5, 6, 7, 8)
packages/goods-management-ui-mt/ (@d8d/goods-management-ui-mt)src/components/GoodsParentChildPanel.tsx、ChildGoodsList.tsx、BatchSpecCreatorInline.tsxpackages/goods-management-ui-mt/src/api/goodsClient.ts@d8d/shared-ui-components (shadcn/ui组件库,46+基础组件)packages/goods-management-ui-mt/tests/unit/ 和 tests/integration/@d8d/shared-ui-components/utils/hc中的rpcClient函数,而不是分别模拟各个客户端管理器vi.mock统一模拟rpcClient函数rpcClient函数,返回包含$get、$post、$put、$delete方法的模拟对象createMockResponse辅助函数生成一致的API响应格式beforeEach或具体测试中配置模拟响应status、ok、json()等方法,确保与实际API响应结构一致@d8d/shared-ui-components包的src/utils/hc.ts文件中export const rpcClient = <T extends Hono<any, any, any>>(aptBaseUrl: string): ReturnType<typeof hc<T>>GoodsParentChildPanel测试失败原因:
getByText导致找到多个元素,应使用更精确的选择器或getAllByText并验证第一个goodsClientManager的残余代码ChildGoodsList测试失败原因:
goodsClientManager而不是统一模拟rpcClientBatchSpecCreatorInline测试失败原因:
goodsClientManager@tanstack/react-query(React Query库),组件测试应使用真实的QueryClient和useQueryClient,确保状态管理逻辑正确sonner(Toast通知库)、lucide-react(图标库)等UI库,可使用最小化模拟BatchSpecCreatorInline、ChildGoodsList),必须使用实际组件进行集成测试
@d8d/shared-ui-components/utils/hc中的rpcClient函数,而不是分别模拟各个客户端管理器@d8d/shared-ui-components/utils/hc中的rpcClient函数$get、$post、$put、$delete方法index)、参数化端点(:id)和属性访问端点(如client.provinces.$get())vi.mock统一模拟rpcClient函数beforeEach中重置rpcClient函数统一拦截packages/goods-management-ui-mt/tests/ 目录下tests/unit/**/*.test.{ts,tsx}tests/integration/**/*.test.{ts,tsx}rpcClient模拟| Date | Version | Description | Author |
|---|---|---|---|
| 2025-12-15 | 1.0 | 初始故事创建 | Bob (Scrum Master) |
| 2025-12-15 | 1.1 | 开始实施测试修复:完成测试失败分析,修复GoodsParentChildPanel文本重复问题 | James |
| 2025-12-15 | 1.2 | 阶段性修复:GoodsParentChildPanel测试11/17通过,ChildGoodsList测试10/14通过,API模拟规范已统一 | James |
| 2025-12-15 | 1.3 | 组件模拟策略明确化:明确React Query必须用真实实现、子组件禁止模拟,移除测试文件中的子组件模拟,为后续修复建立基础 | James |
| 2025-12-15 | 1.4 | 部分修复BatchSpecCreatorInline测试:测试通过率从15/23提高到18/23,修复表单验证交互问题,更新故事文档 | James |
此部分由开发代理在实现过程中填写
测试失败分析完成:
API模拟规范问题识别:
goodsClientManager,不符合统一模拟rpcClient的规范GoodsParentChildPanel测试修复进展:
getAllByText替代getByText下一步工作重点:
ChildGoodsList测试重构进展:
rpcClient函数,移除直接模拟goodsClientManager的代码createMockResponse辅助函数getByTitle多元素问题:使用getAllByTitle处理多个编辑/删除按钮GoodsParentChildPanel测试进一步修复:
getAllByText替代getByTextGoodsParentChildPanel测试最新进展:
getByText('父商品')替换为getAllByText('父商品')[0]/父商品:/匹配文本spuId={-1}使按钮显示,使用getAllByText处理多个按钮getAllByText处理多个"批量创建"标签故事实施当前总结:
rpcClient模拟规范ChildGoodsList测试完全修复:
getByText替换为getAllByText并检查length > 0,解决价格和库存文本重复问题className="animate-spin"fireEvent.change和fireEvent.blur替代userEvent.clear/type,确保表单值正确更新rpcClient模拟规范故事当前状态与后续建议:
rpcClient模拟要求getAllByText替代getByText,检查length > 0fireEvent.change/blur替代userEvent.clear/type组件模拟策略明确化与测试文件更新:
@tanstack/react-query(QueryClient和useQueryClient)必须使用真实实现,确保状态管理逻辑正确BatchSpecCreatorInline、ChildGoodsList)必须使用实际组件进行集成测试,避免掩盖真实交互行为sonner(Toast通知库)、lucide-react(图标库)等UI库允许使用最小化模拟@d8d/shared-ui-components/utils/hc中的rpcClient函数,符合API模拟规范GoodsParentChildPanel.test.tsx中删除BatchSpecCreatorInline和ChildGoodsList的组件模拟,改用真实组件rpcClient模拟和createMockResponse辅助函数BatchSpecCreatorInline测试部分修复进展:
已修改文件:
packages/goods-management-ui-mt/tests/unit/GoodsParentChildPanel.test.tsx
getAllByText处理多个"父商品"元素/父商品:/)spuId={-1}使按钮显示getAllByText处理多个"批量创建"标签rpcClient模拟和createMockResponse辅助函数BatchSpecCreatorInline和ChildGoodsList的模拟,使用真实组件进行集成测试packages/goods-management-ui-mt/tests/unit/ChildGoodsList.test.tsx
rpcClient函数,移除直接模拟goodsClientManagercreateMockResponse辅助函数getByTitle多元素问题:使用getAllByTitle处理多个编辑/删除按钮getByText替换为getAllByText并检查length > 0(价格、库存)className="animate-spin"fireEvent.change/blur确保表单值正确更新fireEvent from '@testing-library/react'以支持表单值更新待修改文件:
packages/goods-management-ui-mt/tests/unit/BatchSpecCreatorInline.test.tsx - 需要按照API模拟规范重构并修复表单验证测试packages/goods-management-ui-mt/tests/unit/BatchSpecCreator.test.tsx - 需要更新API模拟规范packages/goods-management-ui-mt/tests/integration/goods-management.integration.test.tsx - 需要更新API模拟规范此部分由QA代理在审查完成后填写