|
|
@@ -1200,8 +1200,15 @@ describe('残疾人个人管理集成测试', () => {
|
|
|
|
|
|
// 测试1: 验证备注管理组件存在
|
|
|
// 查找备注管理标题或添加按钮
|
|
|
- const remarkTitle = screen.queryByText(/备注管理/i);
|
|
|
- const addRemarkButton = screen.queryByTestId('add-remark-button') || screen.queryByText(/添加备注/i);
|
|
|
+ // 使用queryAllByText来避免MultipleElementsFoundError
|
|
|
+ const remarkTitleMatches = screen.queryAllByText(/备注管理/i);
|
|
|
+ const remarkTitle = remarkTitleMatches.length > 0 ? remarkTitleMatches[0] : null;
|
|
|
+
|
|
|
+ // 查找添加按钮 - 先尝试test-id,再尝试文本
|
|
|
+ const addRemarkButtonByTestId = screen.queryByTestId('add-remark-button');
|
|
|
+ const addRemarkButtonMatches = screen.queryAllByText(/添加备注/i);
|
|
|
+ const addRemarkButtonByText = addRemarkButtonMatches.length > 0 ? addRemarkButtonMatches[0] : null;
|
|
|
+ const addRemarkButton = addRemarkButtonByTestId || addRemarkButtonByText;
|
|
|
|
|
|
if (!remarkTitle && !addRemarkButton) {
|
|
|
console.debug('备注管理组件未找到,可能未集成或需要特定条件显示');
|
|
|
@@ -1294,6 +1301,190 @@ describe('残疾人个人管理集成测试', () => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ it('应该测试回访记录子组件', async () => {
|
|
|
+ renderComponent();
|
|
|
+
|
|
|
+ // 等待数据加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('张三')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 点击新增按钮
|
|
|
+ const addButton = screen.getByTestId('add-disabled-person-button');
|
|
|
+ fireEvent.click(addButton);
|
|
|
+
|
|
|
+ // 验证模态框打开
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByTestId('create-disabled-person-dialog-title')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 首先填写必填字段,以便可以添加回访记录
|
|
|
+ const nameInput = screen.getByPlaceholderText('请输入姓名');
|
|
|
+ const idCardInput = screen.getByPlaceholderText('请输入身份证号');
|
|
|
+ const disabilityIdInput = screen.getByPlaceholderText('请输入残疾证号');
|
|
|
+ const phoneInput = screen.getByPlaceholderText('请输入联系电话');
|
|
|
+ const idAddressInput = screen.getByPlaceholderText('请输入身份证地址');
|
|
|
+
|
|
|
+ fireEvent.change(nameInput, { target: { value: '李四' } });
|
|
|
+ fireEvent.change(idCardInput, { target: { value: '110101199002021234' } });
|
|
|
+ fireEvent.change(disabilityIdInput, { target: { value: 'D123456789' } });
|
|
|
+ fireEvent.change(phoneInput, { target: { value: '13900139000' } });
|
|
|
+ fireEvent.change(idAddressInput, { target: { value: '上海市黄浦区' } });
|
|
|
+
|
|
|
+ // 选择性别
|
|
|
+ const genderSelect = screen.getByTestId('gender-select');
|
|
|
+ fireEvent.change(genderSelect, { target: { value: '女' } });
|
|
|
+
|
|
|
+ // 选择残疾类型
|
|
|
+ const disabilityTypeSelect = screen.getByTestId('disability-type-select');
|
|
|
+ fireEvent.change(disabilityTypeSelect, { target: { value: '视力残疾' } });
|
|
|
+
|
|
|
+ // 选择残疾等级
|
|
|
+ const disabilityLevelSelect = screen.getByTestId('disability-level-select');
|
|
|
+ fireEvent.change(disabilityLevelSelect, { target: { value: '二级' } });
|
|
|
+
|
|
|
+ // 选择省份和城市
|
|
|
+ await act(async () => {
|
|
|
+ await completeRadixSelectFlow('area-select-province', '1', { useFireEvent: true });
|
|
|
+ });
|
|
|
+ await act(async () => {
|
|
|
+ await completeRadixSelectFlow('area-select-city', '3', { useFireEvent: true });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 测试1: 验证回访管理组件存在
|
|
|
+ // 查找回访管理标题或添加按钮
|
|
|
+ // 使用queryAllByText来避免MultipleElementsFoundError
|
|
|
+ const visitTitleMatches = screen.queryAllByText(/回访管理|回访记录/i);
|
|
|
+ const visitTitle = visitTitleMatches.length > 0 ? visitTitleMatches[0] : null;
|
|
|
+
|
|
|
+ // 查找添加按钮 - 先尝试test-id,再尝试文本
|
|
|
+ const addVisitButtonByTestId = screen.queryByTestId('add-visit-button');
|
|
|
+ const addVisitButtonMatches = screen.queryAllByText(/添加回访记录/i);
|
|
|
+ const addVisitButtonByText = addVisitButtonMatches.length > 0 ? addVisitButtonMatches[0] : null;
|
|
|
+ const addVisitButton = addVisitButtonByTestId || addVisitButtonByText;
|
|
|
+
|
|
|
+ if (!visitTitle && !addVisitButton) {
|
|
|
+ console.debug('回访管理组件未找到,可能未集成或需要特定条件显示');
|
|
|
+ return; // 如果组件不存在,跳过测试
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果找到组件,进行测试
|
|
|
+ if (addVisitButton) {
|
|
|
+ // 测试2: 添加回访记录
|
|
|
+ fireEvent.click(addVisitButton);
|
|
|
+
|
|
|
+ // 等待回访表单出现
|
|
|
+ await waitFor(() => {
|
|
|
+ // 查找回访内容输入框
|
|
|
+ const visitContentInputs = screen.queryAllByPlaceholderText(/请输入回访内容|回访内容/i);
|
|
|
+ expect(visitContentInputs.length).toBeGreaterThan(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 查找回访字段
|
|
|
+ const visitContentInputs = screen.queryAllByPlaceholderText(/请输入回访内容|回访内容/i);
|
|
|
+ const lastVisitContentInput = visitContentInputs[visitContentInputs.length - 1];
|
|
|
+
|
|
|
+ if (lastVisitContentInput) {
|
|
|
+ // 填写回访内容
|
|
|
+ fireEvent.change(lastVisitContentInput, { target: { value: '电话回访测试' } });
|
|
|
+
|
|
|
+ // 查找回访日期字段
|
|
|
+ const visitDateInputs = screen.queryAllByPlaceholderText(/请选择回访日期|回访日期/i);
|
|
|
+ if (visitDateInputs.length > 0) {
|
|
|
+ const lastVisitDateInput = visitDateInputs[visitDateInputs.length - 1];
|
|
|
+ // 设置回访日期为今天(格式:YYYY-MM-DD)
|
|
|
+ const today = new Date().toISOString().split('T')[0];
|
|
|
+ fireEvent.change(lastVisitDateInput, { target: { value: today } });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找回访类型选择器
|
|
|
+ const visitTypeSelectors = screen.queryAllByTestId('visit-type-select');
|
|
|
+ if (visitTypeSelectors.length > 0) {
|
|
|
+ const lastVisitTypeSelector = visitTypeSelectors[visitTypeSelectors.length - 1];
|
|
|
+ fireEvent.change(lastVisitTypeSelector, { target: { value: '电话回访' } });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找回访人ID字段
|
|
|
+ const visitorIdInputs = screen.queryAllByPlaceholderText(/回访人ID|请输入回访人ID/i);
|
|
|
+ if (visitorIdInputs.length > 0) {
|
|
|
+ const lastVisitorIdInput = visitorIdInputs[visitorIdInputs.length - 1];
|
|
|
+ fireEvent.change(lastVisitorIdInput, { target: { value: '1' } });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 测试3: 删除回访记录
|
|
|
+ // 查找删除按钮
|
|
|
+ const deleteButtons = screen.queryAllByTestId(/delete-visit|remove-visit/i);
|
|
|
+ if (deleteButtons.length > 0) {
|
|
|
+ const firstDeleteButton = deleteButtons[0];
|
|
|
+ const visitCountBefore = screen.queryAllByPlaceholderText(/请输入回访内容|回访内容/i).length;
|
|
|
+ fireEvent.click(firstDeleteButton);
|
|
|
+
|
|
|
+ // 等待删除生效
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 200));
|
|
|
+
|
|
|
+ const visitCountAfter = screen.queryAllByPlaceholderText(/请输入回访内容|回访内容/i).length;
|
|
|
+ expect(visitCountAfter).toBeLessThan(visitCountBefore);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 测试4: 重新添加回访记录用于提交测试
|
|
|
+ if (visitContentInputs.length === 0) {
|
|
|
+ fireEvent.click(addVisitButton);
|
|
|
+ await waitFor(() => {
|
|
|
+ const newVisitContentInputs = screen.queryAllByPlaceholderText(/请输入回访内容|回访内容/i);
|
|
|
+ expect(newVisitContentInputs.length).toBeGreaterThan(0);
|
|
|
+ });
|
|
|
+ const newVisitContentInputs = screen.queryAllByPlaceholderText(/请输入回访内容|回访内容/i);
|
|
|
+ const newLastVisitContentInput = newVisitContentInputs[newVisitContentInputs.length - 1];
|
|
|
+ fireEvent.change(newLastVisitContentInput, { target: { value: '提交测试回访' } });
|
|
|
+
|
|
|
+ // 填写其他必填字段
|
|
|
+ const newVisitDateInputs = screen.queryAllByPlaceholderText(/请选择回访日期|回访日期/i);
|
|
|
+ if (newVisitDateInputs.length > 0) {
|
|
|
+ const newLastVisitDateInput = newVisitDateInputs[newVisitDateInputs.length - 1];
|
|
|
+ const today = new Date().toISOString().split('T')[0];
|
|
|
+ fireEvent.change(newLastVisitDateInput, { target: { value: today } });
|
|
|
+ }
|
|
|
+
|
|
|
+ const newVisitTypeSelectors = screen.queryAllByTestId('visit-type-select');
|
|
|
+ if (newVisitTypeSelectors.length > 0) {
|
|
|
+ const newLastVisitTypeSelector = newVisitTypeSelectors[newVisitTypeSelectors.length - 1];
|
|
|
+ fireEvent.change(newLastVisitTypeSelector, { target: { value: '上门回访' } });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提交表单并验证API调用包含回访数据
|
|
|
+ const submitButton = screen.getByText('创建');
|
|
|
+ await act(async () => {
|
|
|
+ fireEvent.click(submitButton);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 等待API调用
|
|
|
+ await waitFor(() => {
|
|
|
+ const mockClient = (disabilityClientManager.get as any)();
|
|
|
+ expect(mockClient.createAggregatedDisabledPerson.$post).toHaveBeenCalled();
|
|
|
+ }, { timeout: 3000 });
|
|
|
+
|
|
|
+ // 验证API调用参数包含visits字段
|
|
|
+ const mockClient = (disabilityClientManager.get as any)();
|
|
|
+ const call = mockClient.createAggregatedDisabledPerson.$post.mock.calls[0];
|
|
|
+ if (call && call[0].json) {
|
|
|
+ const submittedData = call[0].json;
|
|
|
+ // 检查是否包含visits字段
|
|
|
+ if (submittedData.visits !== undefined) {
|
|
|
+ expect(Array.isArray(submittedData.visits)).toBe(true);
|
|
|
+ // 如果有回访内容,检查数据结构
|
|
|
+ if (submittedData.visits.length > 0) {
|
|
|
+ expect(submittedData.visits[0]).toHaveProperty('visitDate');
|
|
|
+ expect(submittedData.visits[0]).toHaveProperty('visitType');
|
|
|
+ expect(submittedData.visits[0]).toHaveProperty('visitContent');
|
|
|
+ expect(submittedData.visits[0]).toHaveProperty('visitorId');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
it('应该测试照片上传优化功能', async () => {
|
|
|
renderComponent();
|
|
|
|