Explorar o código

♻️ refactor(tests): 重构残疾人个人管理集成测试的模拟数据

- 移除对 `@d8d/area-management-ui/api` 的直接模拟,改为在 `rpcClient` 模拟中统一处理
- 在 `rpcClient` 模拟中新增 `adminAreas.index.$get` 方法以提供区域数据
- 更新测试用例中的区域选择逻辑,使用区域ID(如 `'1'`, `'3'`, `'5'`)替代硬编码的区域名称(如 `'北京市'`, `'东城区'`)
- 【测试】确保集成测试的模拟数据来源集中化,减少外部依赖
yourname hai 1 semana
pai
achega
7d60ac9231

+ 28 - 40
allin-packages/disability-person-management-ui/tests/integration/disability-person.integration.test.tsx

@@ -309,39 +309,7 @@ vi.mock('sonner', () => ({
 }));
 
 
-// Mock area-management-ui 的 API - 使用简单的mock
-// 注意:我们不再mock UI组件,只mock API
-vi.mock('@d8d/area-management-ui/api', () => ({
-  areaClient: {
-    getAllAreas: {
-      $get: vi.fn(() => Promise.resolve({
-        status: 200,
-        ok: true,
-        body: null,
-        bodyUsed: false,
-        statusText: 'OK',
-        headers: new Headers(),
-        url: '',
-        redirected: false,
-        type: 'basic',
-        json: async () => ({
-          data: [
-            { id: 1, name: '北京市', parentId: null, level: 1 },
-            { id: 2, name: '上海市', parentId: null, level: 1 },
-            { id: 3, name: '东城区', parentId: 1, level: 2 },
-            { id: 4, name: '黄浦区', parentId: 2, level: 2 },
-          ],
-          total: 4
-        }),
-        text: async () => '',
-        blob: async () => new Blob(),
-        arrayBuffer: async () => new ArrayBuffer(0),
-        formData: async () => new FormData(),
-        clone: function() { return this; }
-      })),
-    },
-  },
-}));
+// area-management-ui API mock removed - using rpcClient mock instead
 
 // Mock 共享工具包中的rpcClient函数
 vi.mock('@d8d/shared-ui-components/utils/hc', () => ({
@@ -441,6 +409,26 @@ vi.mock('@d8d/shared-ui-components/utils/hc', () => ({
             pageSize: 10
           })
         }))
+      },
+      adminAreas: {
+        index: {
+          $get: vi.fn(() => {
+            console.debug('rpcClient areas.index.$get called');
+            return Promise.resolve({
+              status: 200,
+              json: async () => ({
+                data: [
+                  { id: 1, name: '北京市', parentId: null, level: 1 },
+                  { id: 2, name: '上海市', parentId: null, level: 1 },
+                  { id: 3, name: '东城区', parentId: 1, level: 2 },
+                  { id: 4, name: '黄浦区', parentId: 2, level: 2 },
+                  { id: 5, name: '东城区街道', parentId: 3, level: 3 },
+                ],
+                total: 5
+              })
+            });
+          })
+        }
       }
     };
 
@@ -537,10 +525,10 @@ describe('残疾人个人管理集成测试', () => {
 
     // 选择省份和城市
     await act(async () => {
-      await completeRadixSelectFlow('area-select-province', '北京市', { useFireEvent: true });
+      await completeRadixSelectFlow('area-select-province', '1', { useFireEvent: true });
     });
     await act(async () => {
-      await completeRadixSelectFlow('area-select-city', '东城区', { useFireEvent: true });
+      await completeRadixSelectFlow('area-select-city', '3', { useFireEvent: true });
     });
 
     // 提交表单
@@ -717,16 +705,16 @@ describe('残疾人个人管理集成测试', () => {
 
     // 选择省份
     await act(async () => {
-      await completeRadixSelectFlow('area-select-province', '北京市', { useFireEvent: true });
+      await completeRadixSelectFlow('area-select-province', '1', { useFireEvent: true });
     });
 
     // 选择城市
     await act(async () => {
-      await completeRadixSelectFlow('area-select-city', '东城区', { useFireEvent: true });
+      await completeRadixSelectFlow('area-select-city', '3', { useFireEvent: true });
     });
 
     // 选择区县
-    await completeRadixSelectFlow('area-select-district', '3', { useFireEvent: true });
+    await completeRadixSelectFlow('area-select-district', '5', { useFireEvent: true });
   });
 
   it('应该测试文件选择器集成', async () => {
@@ -808,10 +796,10 @@ describe('残疾人个人管理集成测试', () => {
 
     // 选择省份和城市
     await act(async () => {
-      await completeRadixSelectFlow('area-select-province', '北京市', { useFireEvent: true });
+      await completeRadixSelectFlow('area-select-province', '1', { useFireEvent: true });
     });
     await act(async () => {
-      await completeRadixSelectFlow('area-select-city', '东城区', { useFireEvent: true });
+      await completeRadixSelectFlow('area-select-city', '3', { useFireEvent: true });
     });
 
     // 提交表单