import { expect, test, type Page, type TestInfo } from "@playwright/test"; import { EMPLOYEE, FINANCE, login, logout, type E2EUser } from "./helpers/auth"; const ADMIN: E2EUser = { identifier: "admin@hyinda.com", password: "AdminPassword1234", name: "Admin", }; async function attachScreenshot(page: Page, testInfo: TestInfo, name: string) { await testInfo.attach(name, { body: await page.screenshot({ fullPage: true }), contentType: "image/png", }); } test.describe("visual portal", () => { test("员工 Portal 视觉基线", async ({ page }, testInfo) => { await page.setViewportSize({ width: 1440, height: 1200 }); await login(page, EMPLOYEE); await expect(page.getByRole("heading", { name: "今日任务" })).toBeVisible(); await expect(page.getByText("当前焦点")).toBeVisible(); await expect(page.getByText("下一步")).toBeVisible(); await expect(page.locator("summary").filter({ hasText: "团队与通知" })).toBeVisible(); await expect(page.locator("summary").filter({ hasText: "更多入口" })).toBeVisible(); await attachScreenshot(page, testInfo, "portal-employee.png"); }); test("管理员 Portal 视觉基线", async ({ page }, testInfo) => { await page.setViewportSize({ width: 1440, height: 1200 }); await login(page, ADMIN); await expect(page.locator('[aria-label="portal-card-pending_approvals"]')).toHaveCount(0); await expect(page.getByRole("heading", { name: "今日任务" })).toBeVisible(); await expect(page.getByText("下一步")).toBeVisible(); await expect(page.locator("summary").filter({ hasText: "团队与通知" })).toBeVisible(); await expect(page.locator("summary").filter({ hasText: "角色重点" })).toBeVisible(); await expect(page.getByText("试点观测摘要")).toBeVisible(); await attachScreenshot(page, testInfo, "portal-admin.png"); await logout(page, ADMIN.name); }); test("财务 Portal 显示财务待处理入口", async ({ page }, testInfo) => { await page.setViewportSize({ width: 1440, height: 1200 }); await login(page, FINANCE); await expect(page.getByText("财务工作台")).toBeVisible(); await expect(page.getByRole("heading", { name: "今日任务" })).toBeVisible(); await expect(page.locator("summary").filter({ hasText: "角色重点" })).toBeVisible(); await attachScreenshot(page, testInfo, "portal-finance.png"); await logout(page, FINANCE.name); }); });