|
|
@@ -310,6 +310,62 @@ vi.mock('@d8d/area-management-ui/components', () => ({
|
|
|
</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 文件选择器组件
|
|
|
@@ -409,8 +465,8 @@ describe('残疾人个人管理集成测试', () => {
|
|
|
fireEvent.change(disabilityLevelSelect, { target: { value: '二级' } });
|
|
|
|
|
|
// 选择省份和城市
|
|
|
- const provinceSelect = screen.getByTestId('province-select');
|
|
|
- const citySelect = screen.getByTestId('city-select');
|
|
|
+ const provinceSelect = screen.getByTestId('province-select-form');
|
|
|
+ const citySelect = screen.getByTestId('city-select-form');
|
|
|
|
|
|
await act(async () => {
|
|
|
fireEvent.change(provinceSelect, { target: { value: '1' } });
|
|
|
@@ -428,6 +484,25 @@ describe('残疾人个人管理集成测试', () => {
|
|
|
fireEvent.click(submitButton);
|
|
|
});
|
|
|
|
|
|
+ // 等待一下,看看是否有验证错误
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
+
|
|
|
+ // 检查是否有验证错误显示
|
|
|
+ const validationErrors = screen.queryAllByText(/不能为空/);
|
|
|
+ if (validationErrors.length > 0) {
|
|
|
+ console.debug('验证错误:', validationErrors.map(err => err.textContent));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查表单字段值
|
|
|
+ console.debug('表单提交状态 - 检查字段值:');
|
|
|
+ const nameInput2 = screen.getByPlaceholderText('请输入姓名');
|
|
|
+ const provinceSelect2 = screen.getByTestId('province-select-form');
|
|
|
+ const citySelect2 = screen.getByTestId('city-select-form');
|
|
|
+
|
|
|
+ console.debug('name:', (nameInput2 as HTMLInputElement).value);
|
|
|
+ console.debug('province select value:', (provinceSelect2 as HTMLSelectElement).value);
|
|
|
+ console.debug('city select value:', (citySelect2 as HTMLSelectElement).value);
|
|
|
+
|
|
|
// 验证API调用 - 增加等待时间
|
|
|
await waitFor(() => {
|
|
|
const mockClient = (disabilityClientManager.get as any)();
|
|
|
@@ -580,18 +655,18 @@ describe('残疾人个人管理集成测试', () => {
|
|
|
});
|
|
|
|
|
|
// 验证区域选择器存在
|
|
|
- expect(screen.getByTestId('area-select')).toBeInTheDocument();
|
|
|
+ expect(screen.getByTestId('area-select-form')).toBeInTheDocument();
|
|
|
|
|
|
// 选择省份
|
|
|
- const provinceSelect = screen.getByTestId('province-select');
|
|
|
+ const provinceSelect = screen.getByTestId('province-select-form');
|
|
|
fireEvent.change(provinceSelect, { target: { value: '1' } });
|
|
|
|
|
|
// 选择城市
|
|
|
- const citySelect = screen.getByTestId('city-select');
|
|
|
+ const citySelect = screen.getByTestId('city-select-form');
|
|
|
fireEvent.change(citySelect, { target: { value: '2' } });
|
|
|
|
|
|
// 选择区县
|
|
|
- const districtSelect = screen.getByTestId('district-select');
|
|
|
+ const districtSelect = screen.getByTestId('district-select-form');
|
|
|
fireEvent.change(districtSelect, { target: { value: '3' } });
|
|
|
});
|
|
|
|