import { test, expect } from '@playwright/test'; import { LoginPage } from '../../../novalon-manage-web/e2e/pages/LoginPage'; import { UserManagementPage } from '../../pages/UserManagementPage'; import { UATHelper } from '../../utils/uat-helper'; import { DataLoader } from '../../utils/data-loader'; test.describe('UAT - 多角色协作场景', () => { let loginPage: LoginPage; let userManagementPage: UserManagementPage; let helper: UATHelper; test('跨部门协作流程', async ({ page, context }) => { const adminUser = DataLoader.getUserByRole('admin'); const managerUser = DataLoader.getUserByRole('manager'); await loginPage.goto(); await loginPage.login(adminUser.username, adminUser.password); await userManagementPage.navigateTo(); await helper.waitForElement('[data-testid="user-table"]'); await userManagementPage.clickCreateUser(); const timestamp = Date.now(); const userData = { username: `collab_user_${timestamp}`, nickname: `协作用户${timestamp}`, email: `collab_${timestamp}@example.com`, department: '技术部', manager: managerUser.username, password: 'Collab123!@#', confirmPassword: 'Collab123!@#', }; await userManagementPage.fillUserForm(userData); await userManagementPage.submitForm(); await helper.verifySuccessMessage('创建成功'); await userManagementPage.logout(); await loginPage.goto(); await loginPage.login(managerUser.username, managerUser.password); await userManagementPage.navigateTo(); await helper.waitForElement('[data-testid="user-table"]'); await expect(userManagementPage.table).toContainText(userData.username); await expect(userManagementPage.table).toContainText(userData.department); await userManagementPage.approveUser(userData.username); await helper.verifySuccessMessage('审批成功'); await userManagementPage.logout(); await loginPage.goto(); await loginPage.login(userData.username, userData.password); await expect(page).toHaveURL(/.*dashboard/); }); test('数据一致性验证', async ({ page, context }) => { const adminUser = DataLoader.getUserByRole('admin'); await loginPage.goto(); await loginPage.login(adminUser.username, adminUser.password); await userManagementPage.navigateTo(); await helper.waitForElement('[data-testid="user-table"]'); const initialCount = await userManagementPage.getUserCount(); await userManagementPage.clickCreateUser(); const timestamp = Date.now(); const userData = { username: `consistency_user_${timestamp}`, nickname: `一致性用户${timestamp}`, email: `consistency_${timestamp}@example.com`, password: 'Consistency123!@#', confirmPassword: 'Consistency123!@#', }; await userManagementPage.fillUserForm(userData); await userManagementPage.submitForm(); await helper.verifySuccessMessage('创建成功'); await helper.waitForPageLoad(); const finalCount = await userManagementPage.getUserCount(); expect(finalCount).toBe(initialCount + 1); await page.reload(); await helper.waitForPageLoad(); const reloadedCount = await userManagementPage.getUserCount(); expect(reloadedCount).toBe(finalCount); }); });