Files
erp/apps/web/e2e/auth.fixture.ts
iven 790991f77c
Some checks are pending
CI / rust-check (push) Waiting to run
CI / rust-test (push) Waiting to run
CI / frontend-build (push) Waiting to run
CI / security-audit (push) Waiting to run
test: E2E auth fixture 修复 + Workflow 集成测试
- E2E: 用 addInitScript 替代 goto+evaluate 注入 localStorage,
  解决 Zustand store 初始化时序问题 (10/10 通过)
- E2E: 修复 Modal 按钮选择器 (OK/Cancel 替代中文)
- E2E: Playwright 配置对齐端口 5174
- 集成测试: 新增 workflow_tests 模块 (4 个测试)
2026-04-18 08:40:33 +08:00

30 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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';