363 lines
12 KiB
TypeScript
363 lines
12 KiB
TypeScript
|
|
/**
|
||
|
|
* 超管端 E2E 测试 - 系统设置
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { test, expect } from '@playwright/test';
|
||
|
|
import { loginAsAdmin } from './helpers';
|
||
|
|
|
||
|
|
test.describe('系统设置', () => {
|
||
|
|
test.beforeEach(async ({ page }) => {
|
||
|
|
await loginAsAdmin(page);
|
||
|
|
// 导航到系统设置页面
|
||
|
|
await page.goto('/admin/settings');
|
||
|
|
});
|
||
|
|
|
||
|
|
test.describe('基本设置', () => {
|
||
|
|
test('访问系统设置页面', async ({ page }) => {
|
||
|
|
// 验证页面 URL
|
||
|
|
await expect(page).toHaveURL(/\/admin\/settings/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('查看基本设置表单', async ({ page }) => {
|
||
|
|
// 验证基本设置标签页激活
|
||
|
|
const basicTab = page.locator('.ant-tabs-tab:has-text("基本设置")');
|
||
|
|
await expect(basicTab).toBeVisible();
|
||
|
|
|
||
|
|
// 验证表单字段存在
|
||
|
|
await expect(page.getByText('系统名称')).toBeVisible();
|
||
|
|
await expect(page.getByText('系统 LOGO')).toBeVisible();
|
||
|
|
await expect(page.getByText('系统简介')).toBeVisible();
|
||
|
|
await expect(page.getByText('联系电话')).toBeVisible();
|
||
|
|
await expect(page.getByText('联系邮箱')).toBeVisible();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('修改系统名称', async ({ page }) => {
|
||
|
|
// 等待表单加载
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 修改系统名称
|
||
|
|
const nameInput = page.locator('input[placeholder*="系统名称"]');
|
||
|
|
if (await nameInput.isVisible()) {
|
||
|
|
const originalName = await nameInput.inputValue();
|
||
|
|
await nameInput.fill(`${originalName}_测试`);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('修改联系电话', async ({ page }) => {
|
||
|
|
// 等待表单加载
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 修改联系电话
|
||
|
|
const phoneInput = page.locator('input[placeholder*="联系电话"]');
|
||
|
|
if (await phoneInput.isVisible()) {
|
||
|
|
await phoneInput.fill('010-12345678');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('修改联系邮箱', async ({ page }) => {
|
||
|
|
// 等待表单加载
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 修改联系邮箱
|
||
|
|
const emailInput = page.locator('input[placeholder*="联系邮箱"]');
|
||
|
|
if (await emailInput.isVisible()) {
|
||
|
|
await emailInput.fill('test@example.com');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('上传系统 Logo', async ({ page }) => {
|
||
|
|
// 等待表单加载
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 验证上传组件存在
|
||
|
|
const uploadButton = page.locator('.ant-upload-picture-card');
|
||
|
|
await expect(uploadButton).toBeVisible();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('保存基本设置', async ({ page }) => {
|
||
|
|
// 等待表单加载
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 修改系统名称
|
||
|
|
const nameInput = page.locator('input[placeholder*="系统名称"]');
|
||
|
|
if (await nameInput.isVisible()) {
|
||
|
|
await nameInput.fill('测试系统名称');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 修改联系电话
|
||
|
|
const phoneInput = page.locator('input[placeholder*="联系电话"]');
|
||
|
|
if (await phoneInput.isVisible()) {
|
||
|
|
await phoneInput.fill('010-12345678');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 修改联系邮箱
|
||
|
|
const emailInput = page.locator('input[placeholder*="联系邮箱"]');
|
||
|
|
if (await emailInput.isVisible()) {
|
||
|
|
await emailInput.fill('test@example.com');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 点击保存按钮
|
||
|
|
const saveButton = page.locator('button:has-text("保存设置")').first();
|
||
|
|
if (await saveButton.isVisible()) {
|
||
|
|
await saveButton.click();
|
||
|
|
|
||
|
|
// 等待保存结果
|
||
|
|
await page.waitForTimeout(2000);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
test.describe('安全设置', () => {
|
||
|
|
test('查看安全设置', async ({ page }) => {
|
||
|
|
// 点击安全设置标签页
|
||
|
|
const securityTab = page.locator('.ant-tabs-tab:has-text("安全设置")');
|
||
|
|
await securityTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 验证表单项存在
|
||
|
|
await expect(page.getByText('密码强度')).toBeVisible();
|
||
|
|
await expect(page.getByText('登录失败限制')).toBeVisible();
|
||
|
|
await expect(page.getByText('Token 有效期')).toBeVisible();
|
||
|
|
await expect(page.getByText('强制 HTTPS')).toBeVisible();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('修改密码强度策略', async ({ page }) => {
|
||
|
|
// 点击安全设置标签页
|
||
|
|
const securityTab = page.locator('.ant-tabs-tab:has-text("安全设置")');
|
||
|
|
await securityTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 选择密码强度
|
||
|
|
const highRadio = page.locator('a-radio:has-text("高")');
|
||
|
|
if (await highRadio.isVisible()) {
|
||
|
|
await highRadio.click();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('修改最大登录尝试次数', async ({ page }) => {
|
||
|
|
// 点击安全设置标签页
|
||
|
|
const securityTab = page.locator('.ant-tabs-tab:has-text("安全设置")');
|
||
|
|
await securityTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 修改登录失败限制
|
||
|
|
const attemptsInput = page.locator('input[type="number"]').first();
|
||
|
|
if (await attemptsInput.isVisible()) {
|
||
|
|
await attemptsInput.fill('3');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('修改 Token 过期时间', async ({ page }) => {
|
||
|
|
// 点击安全设置标签页
|
||
|
|
const securityTab = page.locator('.ant-tabs-tab:has-text("安全设置")');
|
||
|
|
await securityTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 选择 Token 有效期
|
||
|
|
const tokenSelect = page.locator('[placeholder*="Token"]');
|
||
|
|
if (await tokenSelect.isVisible()) {
|
||
|
|
await tokenSelect.click();
|
||
|
|
await page.getByText('30 天').click();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('保存安全设置', async ({ page }) => {
|
||
|
|
// 点击安全设置标签页
|
||
|
|
const securityTab = page.locator('.ant-tabs-tab:has-text("安全设置")');
|
||
|
|
await securityTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 选择密码强度为高
|
||
|
|
const highRadio = page.locator('a-radio:has-text("高")');
|
||
|
|
if (await highRadio.isVisible()) {
|
||
|
|
await highRadio.click();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 点击保存按钮
|
||
|
|
const saveButton = page.locator('button:has-text("保存设置")').last();
|
||
|
|
if (await saveButton.isVisible()) {
|
||
|
|
await saveButton.click();
|
||
|
|
|
||
|
|
// 等待保存结果
|
||
|
|
await page.waitForTimeout(2000);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
test.describe('通知设置', () => {
|
||
|
|
test('查看通知设置', async ({ page }) => {
|
||
|
|
// 点击通知设置标签页
|
||
|
|
const notificationTab = page.locator('.ant-tabs-tab:has-text("通知设置")');
|
||
|
|
await notificationTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 验证表单项存在
|
||
|
|
await expect(page.getByText('邮件通知')).toBeVisible();
|
||
|
|
await expect(page.getByText('邮件服务器')).toBeVisible();
|
||
|
|
await expect(page.getByText('邮件端口')).toBeVisible();
|
||
|
|
await expect(page.getByText('发件人邮箱')).toBeVisible();
|
||
|
|
await expect(page.getByText('短信通知')).toBeVisible();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('启用/禁用邮件通知', async ({ page }) => {
|
||
|
|
// 点击通知设置标签页
|
||
|
|
const notificationTab = page.locator('.ant-tabs-tab:has-text("通知设置")');
|
||
|
|
await notificationTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 切换邮件通知开关
|
||
|
|
const emailSwitch = page.locator('[placeholder*="邮件通知"] + .ant-switch').or(page.locator('.ant-switch').first());
|
||
|
|
if (await emailSwitch.isVisible()) {
|
||
|
|
await emailSwitch.click();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('配置 SMTP 服务器', async ({ page }) => {
|
||
|
|
// 点击通知设置标签页
|
||
|
|
const notificationTab = page.locator('.ant-tabs-tab:has-text("通知设置")');
|
||
|
|
await notificationTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 填写 SMTP 服务器
|
||
|
|
const smtpHostInput = page.locator('input[placeholder*="smtp"]');
|
||
|
|
if (await smtpHostInput.isVisible()) {
|
||
|
|
await smtpHostInput.fill('smtp.example.com');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 填写 SMTP 端口
|
||
|
|
const smtpPortInput = page.locator('input[type="number"]').last();
|
||
|
|
if (await smtpPortInput.isVisible()) {
|
||
|
|
await smtpPortInput.fill('587');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 填写发件人邮箱
|
||
|
|
const fromEmailInput = page.locator('input[placeholder*="发件人"]');
|
||
|
|
if (await fromEmailInput.isVisible()) {
|
||
|
|
await fromEmailInput.fill('noreply@example.com');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('启用/禁用短信通知', async ({ page }) => {
|
||
|
|
// 点击通知设置标签页
|
||
|
|
const notificationTab = page.locator('.ant-tabs-tab:has-text("通知设置")');
|
||
|
|
await notificationTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 切换短信通知开关
|
||
|
|
const smsSwitch = page.locator('[placeholder*="短信通知"] + .ant-switch').or(page.locator('.ant-switch').last());
|
||
|
|
if (await smsSwitch.isVisible()) {
|
||
|
|
await smsSwitch.click();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('保存通知设置', async ({ page }) => {
|
||
|
|
// 点击通知设置标签页
|
||
|
|
const notificationTab = page.locator('.ant-tabs-tab:has-text("通知设置")');
|
||
|
|
await notificationTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 填写 SMTP 服务器
|
||
|
|
const smtpHostInput = page.locator('input[placeholder*="smtp"]');
|
||
|
|
if (await smtpHostInput.isVisible()) {
|
||
|
|
await smtpHostInput.fill('smtp.example.com');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 点击保存按钮
|
||
|
|
const saveButton = page.locator('button:has-text("保存设置")').last();
|
||
|
|
if (await saveButton.isVisible()) {
|
||
|
|
await saveButton.click();
|
||
|
|
|
||
|
|
// 等待保存结果
|
||
|
|
await page.waitForTimeout(2000);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
test.describe('存储设置', () => {
|
||
|
|
test('查看存储设置', async ({ page }) => {
|
||
|
|
// 点击存储设置标签页
|
||
|
|
const storageTab = page.locator('.ant-tabs-tab:has-text("存储设置")');
|
||
|
|
await storageTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 验证表单项存在
|
||
|
|
await expect(page.getByText('存储类型')).toBeVisible();
|
||
|
|
await expect(page.getByText('上传限制')).toBeVisible();
|
||
|
|
await expect(page.getByText('允许的文件类型')).toBeVisible();
|
||
|
|
});
|
||
|
|
|
||
|
|
test('选择存储类型', async ({ page }) => {
|
||
|
|
// 点击存储设置标签页
|
||
|
|
const storageTab = page.locator('.ant-tabs-tab:has-text("存储设置")');
|
||
|
|
await storageTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 选择本地存储
|
||
|
|
const localRadio = page.locator('a-radio:has-text("本地存储")');
|
||
|
|
if (await localRadio.isVisible()) {
|
||
|
|
await localRadio.click();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 或者选择阿里云 OSS
|
||
|
|
const ossRadio = page.locator('a-radio:has-text("阿里云 OSS")');
|
||
|
|
if (await ossRadio.isVisible()) {
|
||
|
|
await ossRadio.click();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('设置最大文件大小', async ({ page }) => {
|
||
|
|
// 点击存储设置标签页
|
||
|
|
const storageTab = page.locator('.ant-tabs-tab:has-text("存储设置")');
|
||
|
|
await storageTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 修改上传限制
|
||
|
|
const maxSizeInput = page.locator('input[type="number"]');
|
||
|
|
if (await maxSizeInput.isVisible()) {
|
||
|
|
await maxSizeInput.fill('50');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('设置允许的文件类型', async ({ page }) => {
|
||
|
|
// 点击存储设置标签页
|
||
|
|
const storageTab = page.locator('.ant-tabs-tab:has-text("存储设置")');
|
||
|
|
await storageTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 修改允许的文件类型
|
||
|
|
const typesInput = page.locator('input[placeholder*="允许的文件类型"]');
|
||
|
|
if (await typesInput.isVisible()) {
|
||
|
|
await typesInput.fill('.jpg,.png,.pdf,.doc,.docx,.mp4');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
test('保存存储设置', async ({ page }) => {
|
||
|
|
// 点击存储设置标签页
|
||
|
|
const storageTab = page.locator('.ant-tabs-tab:has-text("存储设置")');
|
||
|
|
await storageTab.click();
|
||
|
|
await page.waitForTimeout(500);
|
||
|
|
|
||
|
|
// 选择本地存储
|
||
|
|
const localRadio = page.locator('a-radio:has-text("本地存储")');
|
||
|
|
if (await localRadio.isVisible()) {
|
||
|
|
await localRadio.click();
|
||
|
|
}
|
||
|
|
|
||
|
|
// 修改上传限制
|
||
|
|
const maxSizeInput = page.locator('input[type="number"]');
|
||
|
|
if (await maxSizeInput.isVisible()) {
|
||
|
|
await maxSizeInput.fill('50');
|
||
|
|
}
|
||
|
|
|
||
|
|
// 点击保存按钮
|
||
|
|
const saveButton = page.locator('button:has-text("保存设置")').last();
|
||
|
|
if (await saveButton.isVisible()) {
|
||
|
|
await saveButton.click();
|
||
|
|
|
||
|
|
// 等待保存结果
|
||
|
|
await page.waitForTimeout(2000);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});
|