Files
doc_ai_frontend/e2e/auth-email.spec.ts

58 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2026-03-06 14:30:30 +08:00
import { expect, test } from '@playwright/test';
const jwtPayload = Buffer.from(
JSON.stringify({ user_id: 7, email: 'user@example.com', exp: 1999999999, iat: 1111111 })
)
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/g, '');
const token = `header.${jwtPayload}.sig`;
test('email login should authenticate and display user email', async ({ page }) => {
await page.route('**/user/login', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
request_id: 'req_login',
code: 200,
message: 'ok',
data: {
token,
expires_at: 1999999999,
},
}),
});
});
await page.route('**/task/list**', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
request_id: 'req_tasks',
code: 200,
message: 'ok',
data: {
task_list: [],
total: 0,
},
}),
});
});
await page.goto('/');
const loginButton = page.getByRole('button', { name: /Login|登录/ }).first();
await loginButton.click();
await page.fill('#auth-email', 'user@example.com');
await page.fill('#auth-password', '123456');
await page.locator('button[type="submit"]').click();
await expect(page.getByText('user@example.com')).toBeVisible();
});