test: E2E auth fixture 修复 + Workflow 集成测试
- E2E: 用 addInitScript 替代 goto+evaluate 注入 localStorage, 解决 Zustand store 初始化时序问题 (10/10 通过) - E2E: 修复 Modal 按钮选择器 (OK/Cancel 替代中文) - E2E: Playwright 配置对齐端口 5174 - 集成测试: 新增 workflow_tests 模块 (4 个测试)
This commit is contained in:
29
apps/web/e2e/auth.fixture.ts
Normal file
29
apps/web/e2e/auth.fixture.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
const MOCK_USER = {
|
||||
id: '00000000-0000-0000-0000-000000000001',
|
||||
username: 'e2e_admin',
|
||||
display_name: 'E2E 测试管理员',
|
||||
email: 'e2e@test.com',
|
||||
status: 'active',
|
||||
roles: [{ id: '00000000-0000-0000-0000-000000000001', name: '管理员', code: 'admin' }],
|
||||
tenant_id: '00000000-0000-0000-0000-000000000001',
|
||||
};
|
||||
|
||||
const MOCK_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e2e-mock-token';
|
||||
|
||||
// 扩展 test fixture,自动注入认证状态
|
||||
export const test = base.extend({
|
||||
page: async ({ page }, use) => {
|
||||
// 在页面 JavaScript 执行前注入 localStorage
|
||||
// 这样 Zustand store 的 restoreInitialState() 能读到 token
|
||||
await page.addInitScript((args) => {
|
||||
localStorage.setItem('access_token', args.token);
|
||||
localStorage.setItem('refresh_token', args.token);
|
||||
localStorage.setItem('user', JSON.stringify(args.user));
|
||||
}, { token: MOCK_TOKEN, user: MOCK_USER });
|
||||
await use(page);
|
||||
},
|
||||
});
|
||||
|
||||
export { expect } from '@playwright/test';
|
||||
Reference in New Issue
Block a user