|
|
@@ -467,24 +467,58 @@ describe('信用额度管理对话框集成测试', () => {
|
|
|
/>
|
|
|
);
|
|
|
|
|
|
+ // 等待初始数据加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByTestId('total-limit-card')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
// 切换到额度操作标签页
|
|
|
- fireEvent.click(screen.getByText('额度操作'));
|
|
|
+ const user = userEvent.setup();
|
|
|
+ const operationsTab = screen.getByText('额度操作');
|
|
|
+ await user.click(operationsTab);
|
|
|
|
|
|
- // 尝试提交空表单
|
|
|
- fireEvent.click(screen.getByText('设置额度'));
|
|
|
+ // 等待表单渲染 - 使用test ID查找表单卡片
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByTestId('set-limit-form-card')).toBeInTheDocument();
|
|
|
+ });
|
|
|
|
|
|
- // 应该显示验证错误
|
|
|
+ // 先清空输入框(默认值是0,需要清空来触发验证)
|
|
|
+ const totalLimitInput = screen.getByTestId('total-limit-input');
|
|
|
+ await userEvent.clear(totalLimitInput);
|
|
|
+ console.debug('清空输入框后');
|
|
|
+
|
|
|
+ // 尝试提交空表单 - 使用test ID查找按钮
|
|
|
+ const setLimitButton = screen.getByTestId('set-limit-button');
|
|
|
+ console.debug('点击设置额度按钮前,按钮文本:', setLimitButton.textContent);
|
|
|
+
|
|
|
+ // 使用userEvent.click代替fireEvent.click
|
|
|
+ await userEvent.click(setLimitButton);
|
|
|
+ console.debug('点击设置额度按钮后');
|
|
|
+
|
|
|
+ // 等待并检查验证错误
|
|
|
await waitFor(() => {
|
|
|
- expect(screen.getByText('信用额度必须大于0')).toBeInTheDocument();
|
|
|
+ // 检查是否有任何错误消息
|
|
|
+ const errorElements = screen.queryAllByText(/总额度必须大于等于0|总额度必须是有效的数字|Number must be/i);
|
|
|
+ console.debug('找到的错误元素数量:', errorElements.length);
|
|
|
+ if (errorElements.length > 0) {
|
|
|
+ console.debug('第一个错误元素文本:', errorElements[0].textContent);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查FormMessage元素
|
|
|
+ const formMessages = screen.queryAllByRole('alert');
|
|
|
+ console.debug('FormMessage元素数量:', formMessages.length);
|
|
|
+
|
|
|
+ // 现在应该显示中文错误消息
|
|
|
+ expect(screen.getByText(/总额度必须大于等于0|总额度必须是有效的数字/)).toBeInTheDocument();
|
|
|
});
|
|
|
|
|
|
- // 填写无效数据
|
|
|
- fireEvent.change(screen.getByLabelText('信用额度'), { target: { value: '-100' } });
|
|
|
- fireEvent.click(screen.getByText('设置额度'));
|
|
|
+ // 填写无效数据 - 使用test ID查找输入框
|
|
|
+ await userEvent.type(totalLimitInput, '-100');
|
|
|
+ await userEvent.click(setLimitButton);
|
|
|
|
|
|
// 应该显示验证错误
|
|
|
await waitFor(() => {
|
|
|
- expect(screen.getByText('信用额度必须大于0')).toBeInTheDocument();
|
|
|
+ expect(screen.getByText('总额度必须大于等于0')).toBeInTheDocument();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -530,14 +564,28 @@ describe('信用额度管理对话框集成测试', () => {
|
|
|
new Error('设置额度失败')
|
|
|
);
|
|
|
|
|
|
+ // 等待初始数据加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByTestId('total-limit-card')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
// 切换到额度操作标签页
|
|
|
- fireEvent.click(screen.getByText('额度操作'));
|
|
|
+ const user = userEvent.setup();
|
|
|
+ const operationsTab = screen.getByText('额度操作');
|
|
|
+ await user.click(operationsTab);
|
|
|
|
|
|
- // 填写表单
|
|
|
- fireEvent.change(screen.getByLabelText('信用额度'), { target: { value: '15000' } });
|
|
|
+ // 等待表单渲染
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByTestId('set-limit-form-card')).toBeInTheDocument();
|
|
|
+ });
|
|
|
|
|
|
- // 提交表单
|
|
|
- fireEvent.click(screen.getByText('设置额度'));
|
|
|
+ // 填写表单 - 使用test ID查找输入框
|
|
|
+ const totalLimitInput = screen.getByTestId('total-limit-input');
|
|
|
+ fireEvent.change(totalLimitInput, { target: { value: '15000' } });
|
|
|
+
|
|
|
+ // 提交表单 - 使用test ID查找按钮
|
|
|
+ const setLimitButton = screen.getByTestId('set-limit-button');
|
|
|
+ fireEvent.click(setLimitButton);
|
|
|
|
|
|
await waitFor(() => {
|
|
|
expect(toast.error).toHaveBeenCalledWith('设置额度失败');
|
|
|
@@ -576,26 +624,40 @@ describe('信用额度管理对话框集成测试', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ // 等待初始数据加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByTestId('total-limit-card')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
// 测试带租户ID的操作
|
|
|
(creditBalanceClient[':userId'].$put as any).mockResolvedValue(
|
|
|
createMockResponse(200, { success: true })
|
|
|
);
|
|
|
|
|
|
// 切换到额度操作标签页
|
|
|
- fireEvent.click(screen.getByText('额度操作'));
|
|
|
+ const user = userEvent.setup();
|
|
|
+ const operationsTab = screen.getByText('额度操作');
|
|
|
+ await user.click(operationsTab);
|
|
|
|
|
|
- // 填写表单
|
|
|
- fireEvent.change(screen.getByLabelText('信用额度'), { target: { value: '15000' } });
|
|
|
+ // 等待表单渲染
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByTestId('set-limit-form-card')).toBeInTheDocument();
|
|
|
+ });
|
|
|
|
|
|
- // 提交表单
|
|
|
- fireEvent.click(screen.getByText('设置额度'));
|
|
|
+ // 填写表单 - 使用test ID查找输入框
|
|
|
+ const totalLimitInput = screen.getByTestId('total-limit-input');
|
|
|
+ fireEvent.change(totalLimitInput, { target: { value: '15000' } });
|
|
|
+
|
|
|
+ // 提交表单 - 使用test ID查找按钮
|
|
|
+ const setLimitButton = screen.getByTestId('set-limit-button');
|
|
|
+ fireEvent.click(setLimitButton);
|
|
|
|
|
|
await waitFor(() => {
|
|
|
expect(creditBalanceClient[':userId'].$put).toHaveBeenCalledWith({
|
|
|
param: { userId: '123' },
|
|
|
json: {
|
|
|
totalLimit: 15000,
|
|
|
- isEnabled: 1
|
|
|
+ remark: ''
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
@@ -628,7 +690,7 @@ describe('信用额度管理对话框集成测试', () => {
|
|
|
|
|
|
// 等待数据加载
|
|
|
await waitFor(() => {
|
|
|
- expect(screen.getByText('总额度')).toBeInTheDocument();
|
|
|
+ expect(screen.getByTestId('total-limit-card')).toBeInTheDocument();
|
|
|
});
|
|
|
|
|
|
// 应该显示欠款警告
|