/** * E2E 测试 — 投资人端 Sidebar 6 业务域导航验证。 * * 覆盖 2-task-uiux.md 中 P0#1-2 任务的导航架构重构: * - 6 业务域分组(今日/组合/工作/增长/洞察/报告) * - 底部固定设置入口 * - Sidebar 链接可导航到目标页面 * * 前置条件:后端 http://localhost:8000 + 前端 http://localhost:3000 已启动。 */ import { test, expect, type Page } from "@playwright/test"; const API_BASE = "http://localhost:8000/api/v1"; const TEST_EMAIL = `e2e_sidebar_${Date.now()}@example.com`; const TEST_PASSWORD = "password123"; /** 注册投资人用户并登录。 */ async function loginAsInvestor(page: Page) { await fetch(`${API_BASE}/auth/register`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: TEST_EMAIL, password: TEST_PASSWORD, name: "E2E Sidebar 用户", tenant_name: "E2E Sidebar 机构", role: "investor", }), }); await page.goto("/login"); await page.fill('input[id="email"]', TEST_EMAIL); await page.fill('input[id="password"]', TEST_PASSWORD); await page.click('button[type="submit"]'); } test.describe("投资人端 Sidebar 导航域", () => { test.use({ viewport: { width: 1280, height: 720 } }); test("Sidebar 应包含 6 个业务域分组", async ({ page }: { page: Page }) => { await loginAsInvestor(page); const sidebar = page.locator("aside.hidden.md\\:block"); await expect(sidebar).toBeVisible(); // 6 业务域标题 await expect(sidebar.locator("text=今日").first()).toBeVisible(); await expect(sidebar.locator("text=组合").first()).toBeVisible(); await expect(sidebar.locator("text=工作").first()).toBeVisible(); await expect(sidebar.locator("text=增长").first()).toBeVisible(); await expect(sidebar.locator("text=洞察").first()).toBeVisible(); await expect(sidebar.locator("text=报告").first()).toBeVisible(); }); test("Sidebar 底部应包含设置入口", async ({ page }: { page: Page }) => { await loginAsInvestor(page); const sidebar = page.locator("aside.hidden.md\\:block"); await expect(sidebar.locator("text=设置")).toBeVisible(); }); test("点击今日行动中心应导航到 /today", async ({ page }: { page: Page }) => { await loginAsInvestor(page); await page.locator("aside.hidden.md\\:block").locator("a[href='/today']").click(); await expect(page).toHaveURL(/\/today/); await expect(page.locator("h1")).toContainText("今日行动中心"); }); test("点击多企业对比应导航到 /compare", async ({ page }: { page: Page }) => { await loginAsInvestor(page); await page.locator("aside.hidden.md\\:block").locator("a[href='/compare']").click(); await expect(page).toHaveURL(/\/compare/); }); test("点击决策线程应导航到 /threads", async ({ page }: { page: Page }) => { await loginAsInvestor(page); await page.locator("aside.hidden.md\\:block").locator("a[href='/threads']").click(); await expect(page).toHaveURL(/\/threads/); await expect(page.locator("h1")).toContainText("决策线程"); }); test("点击设置应导航到 /settings", async ({ page }: { page: Page }) => { await loginAsInvestor(page); await page.locator("aside.hidden.md\\:block").locator("a[href='/settings']").click(); await expect(page).toHaveURL(/\/settings/); }); });