Переглянути джерело

更新故事006.020:修复测试数据结构与API模拟规范

- 修复子商品测试数据缺少parent对象的问题,添加parent对象
- 恢复被注释的UI检查,确保子商品显示父商品名称
- 修复剩余的直接使用goodsClient问题,统一使用goodsClientManager.get()
- 更新故事文件完成注释和文件列表
- 验证所有集成测试通过(14/14)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 1 місяць тому
батько
коміт
2936a5c61c

+ 4 - 3
docs/stories/006.020.goods-management-integration-test-api-mock-normalization.story.md

@@ -143,13 +143,14 @@ Claude Sonnet
 3. **API响应配置完成**:商品管理UI包组件的API响应已正确配置,其他UI包组件已通过组件模拟处理。
 4. **验证完成**:运行所有集成测试通过(14/14),API模拟工作正常。
 5. **测试稳定性**:集成测试运行稳定,无flaky tests。
-6. **注意事项**:组件未显示"父商品: 父商品1"文本,已注释掉相关检查,需要后续调查UI组件实现。
+6. **已修复**:组件未显示"父商品: 父商品1"文本的问题已修复,修复测试数据结构,添加parent对象,恢复UI检查。
+7. **完整性验证**:运行完整测试套件验证,14个集成测试全部通过,API模拟规范符合要求,父子商品显示功能正常。
 
 ### File List
 1. `packages/goods-management-ui-mt/tests/integration/goods-management.integration.test.tsx` - 更新API模拟规范:
    - 修复直接使用`goodsClient`的问题,改为使用`goodsClientManager.get()`保持一致性
-   - 注释掉有问题的UI检查(组件未显示"父商品: 父商品1"文本)
-   - 确保统一的rpcClient模拟正常工作
+   - 修复测试数据结构不匹配问题,为子商品添加parent对象,恢复被注释的UI检查
+   - 确保统一的rpcClient模拟正常工作,所有集成测试通过
 
 ## QA Results
 *此部分由QA代理在审查完成后填写*

+ 6 - 5
packages/goods-management-ui-mt/tests/integration/goods-management.integration.test.tsx

@@ -275,13 +275,13 @@ describe('商品管理集成测试', () => {
     fireEvent.change(updateNameInput, { target: { value: '更新后的商品' } });
 
     // Mock successful update
-    (goodsClient[':id']['$put'] as any).mockResolvedValue(createMockResponse(200));
+    (goodsClientManager.get()[':id']['$put'] as any).mockResolvedValue(createMockResponse(200));
 
     const updateButton = screen.getByText('更新');
     fireEvent.click(updateButton);
 
     await waitFor(() => {
-      expect(goodsClient[':id']['$put']).toHaveBeenCalled();
+      expect(goodsClientManager.get()[':id']['$put']).toHaveBeenCalled();
       expect(toast.success).toHaveBeenCalledWith('商品更新成功');
     });
 
@@ -293,7 +293,7 @@ describe('商品管理集成测试', () => {
     expect(screen.getByText('确认删除')).toBeInTheDocument();
 
     // Mock successful deletion
-    (goodsClient[':id']['$delete'] as any).mockResolvedValue({
+    (goodsClientManager.get()[':id']['$delete'] as any).mockResolvedValue({
       status: 204,
     });
 
@@ -301,7 +301,7 @@ describe('商品管理集成测试', () => {
     fireEvent.click(confirmDeleteButton);
 
     await waitFor(() => {
-      expect(goodsClient[':id']['$delete']).toHaveBeenCalled();
+      expect(goodsClientManager.get()[':id']['$delete']).toHaveBeenCalled();
       expect(toast.success).toHaveBeenCalledWith('商品删除成功');
     });
   });
@@ -534,6 +534,7 @@ describe('商品管理集成测试', () => {
             price: 120.00,
             spuId: 1,
             spuName: '父商品1',
+            parent: { id: 1, name: '父商品1' },
             childGoodsIds: [],
             stock: 50,
             salesNum: 5,
@@ -606,7 +607,7 @@ describe('商品管理集成测试', () => {
       // 验证子商品标识显示
       expect(screen.getByText('子商品')).toBeInTheDocument();
       // TODO: 组件可能没有显示父商品名称,暂时注释掉这个检查
-      // expect(screen.getByText(/父商品[::]\s*父商品1/)).toBeInTheDocument();
+      expect(screen.getByText(/父商品[::]\s*父商品1/)).toBeInTheDocument();
     });
 
     it('应该处理筛选器与搜索参数的协同工作', async () => {