Browse Source

chore(disability-person-management-ui): 更新测试mock以匹配组件API变更

- 移除AreaSelectForm组件中不再使用的setValue属性
- 更新测试mock使用新的测试工具
- 保持测试与组件API的一致性

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

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 2 weeks ago
parent
commit
2a87923963

+ 5 - 87
allin-packages/disability-person-management-ui/tests/integration/disability-person.integration.test.tsx

@@ -280,93 +280,11 @@ vi.mock('@d8d/allin-enums', () => ({
   }),
 }));
 
-// Mock 区域选择器组件
-vi.mock('@d8d/area-management-ui/components', () => ({
-  AreaSelect: vi.fn(({ value, onChange }) => (
-    <div data-testid="area-select">
-      <select
-        data-testid="province-select"
-        value={value?.provinceId || ''}
-        onChange={(e) => onChange({ ...value, provinceId: e.target.value ? Number(e.target.value) : undefined })}
-      >
-        <option value="">选择省份</option>
-        <option value="1">北京市</option>
-      </select>
-      <select
-        data-testid="city-select"
-        value={value?.cityId || ''}
-        onChange={(e) => onChange({ ...value, cityId: e.target.value ? Number(e.target.value) : undefined })}
-      >
-        <option value="">选择城市</option>
-        <option value="2">北京市</option>
-      </select>
-      <select
-        data-testid="district-select"
-        value={value?.districtId || ''}
-        onChange={(e) => onChange({ ...value, districtId: e.target.value ? Number(e.target.value) : undefined })}
-      >
-        <option value="">选择区县</option>
-        <option value="3">东城区</option>
-      </select>
-    </div>
-  )),
-  AreaSelectForm: vi.fn(({ provinceName, cityName, districtName, control, setValue }) => {
-    // 模拟 AreaSelectForm 的行为
-    // 使用简单的模拟值
-    const provinceValue = '1';
-    const cityValue = '2';
-    const districtValue = districtName ? '3' : '';
-
-    // 模拟 setValue 调用
-    const mockSetValue = vi.fn();
-
-    return (
-      <div data-testid="area-select-form">
-        <select
-          data-testid="province-select-form"
-          value={provinceValue}
-          onChange={(e) => {
-            if (setValue) {
-              setValue(provinceName, e.target.value, { shouldValidate: true });
-            }
-            mockSetValue(provinceName, e.target.value, { shouldValidate: true });
-          }}
-        >
-          <option value="">选择省份</option>
-          <option value="1">北京市</option>
-        </select>
-        <select
-          data-testid="city-select-form"
-          value={cityValue}
-          onChange={(e) => {
-            if (setValue) {
-              setValue(cityName, e.target.value, { shouldValidate: true });
-            }
-            mockSetValue(cityName, e.target.value, { shouldValidate: true });
-          }}
-        >
-          <option value="">选择城市</option>
-          <option value="2">北京市</option>
-        </select>
-        {districtName && (
-          <select
-            data-testid="district-select-form"
-            value={districtValue}
-            onChange={(e) => {
-              if (setValue) {
-                setValue(districtName, e.target.value, { shouldValidate: true });
-              }
-              mockSetValue(districtName, e.target.value, { shouldValidate: true });
-            }}
-          >
-            <option value="">选择区县</option>
-            <option value="3">东城区</option>
-          </select>
-        )}
-      </div>
-    );
-  }),
-}));
+// Mock area-management-ui 的 API - 使用新的测试工具
+// 注意:我们不再mock UI组件,只mock API
+import { createAreaClientMock } from '@d8d/area-management-ui/test-utils';
+
+vi.mock('@d8d/area-management-ui/api', () => createAreaClientMock());
 
 // Mock 文件选择器组件
 vi.mock('@d8d/file-management-ui/components', () => ({