|
|
@@ -332,4 +332,154 @@ describe('PlatformManagement 集成测试', () => {
|
|
|
expect(screen.getByText('平台管理')).toBeInTheDocument();
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ // 邮箱字段优化测试
|
|
|
+ it('应该允许邮箱字段为空创建平台', async () => {
|
|
|
+ renderComponent();
|
|
|
+
|
|
|
+ // 等待数据加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('测试平台')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 打开创建模态框
|
|
|
+ const createButton = screen.getByTestId('create-platform-button');
|
|
|
+ fireEvent.click(createButton);
|
|
|
+
|
|
|
+ // 填写表单,不填写邮箱字段
|
|
|
+ const platformNameInput = screen.getByTestId('platform-name-input');
|
|
|
+ const contactPersonInput = screen.getByTestId('contact-person-input');
|
|
|
+ const contactPhoneInput = screen.getByTestId('contact-phone-input');
|
|
|
+
|
|
|
+ fireEvent.change(platformNameInput, { target: { value: '新平台(无邮箱)' } });
|
|
|
+ fireEvent.change(contactPersonInput, { target: { value: '李四' } });
|
|
|
+ fireEvent.change(contactPhoneInput, { target: { value: '13900139000' } });
|
|
|
+
|
|
|
+ // 提交表单
|
|
|
+ const submitButton = screen.getByTestId('create-submit-button');
|
|
|
+ fireEvent.click(submitButton);
|
|
|
+
|
|
|
+ // 验证API调用,邮箱字段应为undefined
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(platformClientManager.get().createPlatform.$post).toHaveBeenCalledWith({
|
|
|
+ json: {
|
|
|
+ platformName: '新平台(无邮箱)',
|
|
|
+ contactPerson: '李四',
|
|
|
+ contactPhone: '13900139000',
|
|
|
+ contactEmail: undefined
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('应该允许邮箱字段为有效邮箱格式创建平台', async () => {
|
|
|
+ renderComponent();
|
|
|
+
|
|
|
+ // 等待数据加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('测试平台')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 打开创建模态框
|
|
|
+ const createButton = screen.getByTestId('create-platform-button');
|
|
|
+ fireEvent.click(createButton);
|
|
|
+
|
|
|
+ // 填写表单,包含有效邮箱
|
|
|
+ const platformNameInput = screen.getByTestId('platform-name-input');
|
|
|
+ const contactPersonInput = screen.getByTestId('contact-person-input');
|
|
|
+ const contactPhoneInput = screen.getByTestId('contact-phone-input');
|
|
|
+ const contactEmailInput = screen.getByTestId('contact-email-input');
|
|
|
+
|
|
|
+ fireEvent.change(platformNameInput, { target: { value: '新平台(有邮箱)' } });
|
|
|
+ fireEvent.change(contactPersonInput, { target: { value: '王五' } });
|
|
|
+ fireEvent.change(contactPhoneInput, { target: { value: '13700137000' } });
|
|
|
+ fireEvent.change(contactEmailInput, { target: { value: 'wangwu@example.com' } });
|
|
|
+
|
|
|
+ // 提交表单
|
|
|
+ const submitButton = screen.getByTestId('create-submit-button');
|
|
|
+ fireEvent.click(submitButton);
|
|
|
+
|
|
|
+ // 验证API调用
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(platformClientManager.get().createPlatform.$post).toHaveBeenCalledWith({
|
|
|
+ json: {
|
|
|
+ platformName: '新平台(有邮箱)',
|
|
|
+ contactPerson: '王五',
|
|
|
+ contactPhone: '13700137000',
|
|
|
+ contactEmail: 'wangwu@example.com'
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('应该显示无效邮箱格式的错误提示', async () => {
|
|
|
+ renderComponent();
|
|
|
+
|
|
|
+ // 等待数据加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('测试平台')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 打开创建模态框
|
|
|
+ const createButton = screen.getByTestId('create-platform-button');
|
|
|
+ fireEvent.click(createButton);
|
|
|
+
|
|
|
+ // 填写表单,包含无效邮箱
|
|
|
+ const platformNameInput = screen.getByTestId('platform-name-input');
|
|
|
+ const contactEmailInput = screen.getByTestId('contact-email-input');
|
|
|
+
|
|
|
+ fireEvent.change(platformNameInput, { target: { value: '测试平台' } });
|
|
|
+ fireEvent.change(contactEmailInput, { target: { value: '无效邮箱' } });
|
|
|
+
|
|
|
+ // 提交表单
|
|
|
+ const submitButton = screen.getByTestId('create-submit-button');
|
|
|
+ fireEvent.click(submitButton);
|
|
|
+
|
|
|
+ // 验证显示中文错误提示
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('请输入有效的邮箱地址')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 验证API没有被调用
|
|
|
+ expect(platformClientManager.get().createPlatform.$post).not.toHaveBeenCalled();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('应该允许邮箱字段为空更新平台', async () => {
|
|
|
+ renderComponent();
|
|
|
+
|
|
|
+ // 等待数据加载
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByText('测试平台')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 打开编辑模态框
|
|
|
+ const editButton = screen.getByTestId('edit-button-1');
|
|
|
+ fireEvent.click(editButton);
|
|
|
+
|
|
|
+ // 等待编辑模态框打开
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(screen.getByTestId('edit-platform-dialog-title')).toBeInTheDocument();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 清空邮箱字段
|
|
|
+ const contactEmailInput = screen.getByTestId('contact-email-input');
|
|
|
+ fireEvent.change(contactEmailInput, { target: { value: '' } });
|
|
|
+
|
|
|
+ // 提交表单
|
|
|
+ const submitButton = screen.getByTestId('update-submit-button');
|
|
|
+ fireEvent.click(submitButton);
|
|
|
+
|
|
|
+ // 验证API调用,邮箱字段应为undefined
|
|
|
+ await waitFor(() => {
|
|
|
+ expect(platformClientManager.get().updatePlatform.$post).toHaveBeenCalledWith({
|
|
|
+ json: {
|
|
|
+ id: 1,
|
|
|
+ platformName: '测试平台',
|
|
|
+ contactPerson: '张三',
|
|
|
+ contactPhone: '13800138000',
|
|
|
+ contactEmail: undefined
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|