08ea5fbe98
添加用户管理视图、API和状态管理文件
116 lines
4.5 KiB
TypeScript
116 lines
4.5 KiB
TypeScript
import { test } from '@playwright/test';
|
|
import { test as uatTest } from './uat-base';
|
|
import { LoginPage } from '../pages/login-page';
|
|
import { DashboardPage } from '../pages/dashboard-page';
|
|
import { UserManagementPage } from '../pages/user-management-page';
|
|
import { testConfig } from '../core/test-config';
|
|
|
|
uatTest.describe('UAT-002: 用户管理功能', () => {
|
|
let loginPage: LoginPage;
|
|
let dashboardPage: DashboardPage;
|
|
let userManagementPage: UserManagementPage;
|
|
|
|
test.beforeEach(async ({ page, uatLogin, uatDashboard, uatUserManagement }) => {
|
|
loginPage = uatLogin;
|
|
dashboardPage = uatDashboard;
|
|
userManagementPage = uatUserManagement;
|
|
|
|
await page.goto(testConfig.getBaseURL());
|
|
await loginPage.login('admin', 'admin123');
|
|
await expect(page).toHaveURL(/.*dashboard/);
|
|
});
|
|
|
|
uatTest('UAT-002-01: 查看用户列表', async ({ page }) => {
|
|
await test.step('Given 用户已登录系统', async () => {
|
|
await expect(page).toHaveURL(/.*dashboard/);
|
|
});
|
|
|
|
await test.step('When 用户导航到用户管理页面', async () => {
|
|
await dashboardPage.navigateToUserManagement();
|
|
});
|
|
|
|
await test.step('Then 用户应看到用户列表', async () => {
|
|
await expect(page.locator('[data-testid="user-table"]')).toBeVisible();
|
|
await expect(page.locator('[data-testid="page-title"]')).toContainText('用户管理');
|
|
});
|
|
});
|
|
|
|
uatTest('UAT-002-02: 创建新用户', async ({ page }) => {
|
|
const testUsername = `testuser_${Date.now()}`;
|
|
const testEmail = `testuser_${Date.now()}@example.com`;
|
|
|
|
await test.step('Given 用户在用户管理页面', async () => {
|
|
await dashboardPage.navigateToUserManagement();
|
|
await expect(page.locator('[data-testid="user-table"]')).toBeVisible();
|
|
});
|
|
|
|
await test.step('When 用户点击新增用户按钮并填写信息', async () => {
|
|
await userManagementPage.clickAddUser();
|
|
await userManagementPage.fillUserForm({
|
|
username: testUsername,
|
|
email: testEmail,
|
|
password: 'Test@123456',
|
|
confirmPassword: 'Test@123456',
|
|
role: 'USER',
|
|
status: 'ACTIVE'
|
|
});
|
|
await userManagementPage.submitUserForm();
|
|
});
|
|
|
|
await test.step('Then 新用户应创建成功', async () => {
|
|
await expect(page.locator('.ant-message-success')).toBeVisible();
|
|
await expect(page.locator('.ant-message-success')).toContainText('用户创建成功');
|
|
});
|
|
});
|
|
|
|
uatTest('UAT-002-03: 编辑用户信息', async ({ page }) => {
|
|
await test.step('Given 用户在用户管理页面', async () => {
|
|
await dashboardPage.navigateToUserManagement();
|
|
await expect(page.locator('[data-testid="user-table"]')).toBeVisible();
|
|
});
|
|
|
|
await test.step('When 用户点击编辑按钮并修改信息', async () => {
|
|
await page.click('button:has-text("编辑")');
|
|
await page.fill('[data-testid="email-input"]', 'updated@example.com');
|
|
await page.click('[data-testid="submit-button"]');
|
|
});
|
|
|
|
await test.step('Then 用户信息应更新成功', async () => {
|
|
await expect(page.locator('.ant-message-success')).toBeVisible();
|
|
await expect(page.locator('.ant-message-success')).toContainText('用户更新成功');
|
|
});
|
|
});
|
|
|
|
uatTest('UAT-002-04: 删除用户', async ({ page }) => {
|
|
await test.step('Given 用户在用户管理页面', async () => {
|
|
await dashboardPage.navigateToUserManagement();
|
|
await expect(page.locator('[data-testid="user-table"]')).toBeVisible();
|
|
});
|
|
|
|
await test.step('When 用户点击删除按钮并确认', async () => {
|
|
await page.click('button:has-text("删除")');
|
|
await page.click('.ant-modal-confirm-btn');
|
|
});
|
|
|
|
await test.step('Then 用户应删除成功', async () => {
|
|
await expect(page.locator('.ant-message-success')).toBeVisible();
|
|
await expect(page.locator('.ant-message-success')).toContainText('用户删除成功');
|
|
});
|
|
});
|
|
|
|
uatTest('UAT-002-05: 搜索用户', async ({ page }) => {
|
|
await test.step('Given 用户在用户管理页面', async () => {
|
|
await dashboardPage.navigateToUserManagement();
|
|
await expect(page.locator('[data-testid="user-table"]')).toBeVisible();
|
|
});
|
|
|
|
await test.step('When 用户输入用户名进行搜索', async () => {
|
|
await page.fill('[data-testid="username-search-input"]', 'admin');
|
|
await page.click('[data-testid="search-button"]');
|
|
});
|
|
|
|
await test.step('Then 系统应显示匹配的用户', async () => {
|
|
await expect(page.locator('[data-testid="user-table"]')).toBeVisible();
|
|
});
|
|
});
|
|
}); |