kindergarten_java/reading-platform-frontend/tests/e2e-login-flows.spec.ts
2026-02-28 06:44:56 +08:00

70 lines
1.7 KiB
TypeScript

import { test, expect, Page } from '@playwright/test';
type RoleKey = 'admin' | 'school' | 'teacher' | 'parent';
const ROLE_CONFIG: Record<
RoleKey,
{
label: string;
account: string;
password: string;
dashboardPath: string;
}
> = {
admin: {
label: '超管',
account: 'admin',
password: 'admin123',
dashboardPath: '/admin/dashboard',
},
school: {
label: '学校',
account: 'school',
password: '123456',
dashboardPath: '/school/dashboard',
},
teacher: {
label: '教师',
account: 'teacher1',
password: '123456',
dashboardPath: '/teacher/dashboard',
},
parent: {
label: '家长',
account: 'parent1',
password: '123456',
dashboardPath: '/parent/dashboard',
},
};
async function loginAsRole(page: Page, role: RoleKey) {
const cfg = ROLE_CONFIG[role];
await page.goto('/login');
await page.getByText(cfg.label).click();
await page.getByPlaceholder('请输入账号').fill(cfg.account);
await page.getByPlaceholder('请输入密码').fill(cfg.password);
await page.getByRole('button', { name: '登录' }).click();
await page.waitForURL(`**${cfg.dashboardPath}*`);
await expect(page).toHaveURL(new RegExp(`${cfg.dashboardPath}`));
await expect(page).toHaveTitle(/幼儿阅读教学服务平台/);
}
test.describe('从登录开始的一键全角色流程', () => {
for (const role of Object.keys(ROLE_CONFIG) as RoleKey[]) {
test(`角色:${ROLE_CONFIG[role].label} 登录并进入首页`, async ({ page }) => {
await loginAsRole(page, role);
await expect(page.getByText('数据看板').or(page.getByText('首页'))).toBeVisible({
timeout: 10_000,
});
});
}
});