import { test, expect } from "@playwright/test"; test.describe("站点冒烟", () => { test("首页可访问且无致命前端错误", async ({ page }) => { const pageErrors: string[] = []; page.on("pageerror", (err) => { pageErrors.push(err.message); }); const response = await page.goto("/", { waitUntil: "networkidle" }); expect(response?.ok()).toBeTruthy(); await expect(page.locator("main")).toBeVisible(); await expect(page).toHaveTitle(/海宇数科/); await expect(page.getByRole("heading", { level: 1 })).toContainText( /智能报告/, ); await expect(page.locator("#reports")).toBeVisible(); await expect(page.getByText("企业综合风险报告")).toBeVisible(); const exampleBtn = page .locator("#reports") .getByRole("button", { name: "查看智能体报告示例" }) .first(); await exampleBtn.scrollIntoViewIfNeeded(); await exampleBtn.click({ force: true }); await expect(page.locator(".report-example-overlay")).toBeVisible({ timeout: 10_000, }); await expect(page.locator(".report-example-overlay")).toContainText( "敬请期待", ); await page .locator(".report-example-overlay") .getByRole("button", { name: "关闭" }) .click(); await expect(page.locator(".report-example-overlay")).toHaveCount(0); await expect(page.locator("#models")).toBeVisible(); const businessConsult = page.getByRole("button", { name: "商务咨询" }); await businessConsult.scrollIntoViewIfNeeded(); await expect(businessConsult).toBeVisible(); await businessConsult.click(); await expect( page.getByRole("dialog", { name: "商务咨询" }), ).toContainText("扫描二维码"); await page.getByRole("button", { name: "关闭" }).click(); const squareLink = page.getByRole("link", { name: "模型广场" }).first(); await squareLink.click(); await expect(page).toHaveURL(/\/models$/); await expect(page.getByRole("heading", { level: 1 })).toContainText( "模型广场", ); await expect(page.getByText("minimax-m2.7-highspeed")).toBeVisible(); await expect(page.getByText("glm-5.1")).toBeVisible(); await page.goto("/news", { waitUntil: "domcontentloaded" }); await expect(page.getByRole("heading", { level: 1 })).toContainText( "AI 新闻资讯", ); await page .getByRole("link", { name: "用户协议与隐私政策正式发布" }) .first() .click(); await expect(page).toHaveURL(/\/news\/legal-policies-published/); await expect(page.getByRole("heading", { level: 1 })).toContainText( "用户协议与隐私政策正式发布", ); expect( pageErrors, pageErrors.length ? pageErrors.join("\n") : undefined, ).toEqual([]); }); test("窄屏显示移动菜单并可展开导航", async ({ page }) => { await page.setViewportSize({ width: 390, height: 844 }); await page.goto("/", { waitUntil: "domcontentloaded" }); await expect(page.getByRole("button", { name: "菜单" })).toBeVisible(); await page.getByRole("button", { name: "菜单" }).click(); await expect(page.getByRole("link", { name: "智能报告" }).first()).toBeVisible(); await page.getByRole("link", { name: "模型能力" }).first().click(); await expect(page).toHaveURL(/\/models\/?$/); }); test("文档中心可访问并展示侧栏与示例正文", async ({ page }) => { const response = await page.goto("/docs", { waitUntil: "domcontentloaded", }); expect(response?.ok()).toBeTruthy(); await expect(page).toHaveTitle(/文档中心/); await expect( page.getByRole("region", { name: "文档导航" }), ).toBeVisible(); await expect( page.getByRole("navigation", { name: "面包屑" }), ).toContainText("文档中心"); await expect( page.getByRole("complementary", { name: "文档目录" }).or( page.getByRole("navigation", { name: "文档目录(移动端)" }), ), ).toBeVisible({ timeout: 15_000 }); await expect(page.getByRole("link", { name: "快速开始" }).first()).toBeVisible(); await page.getByRole("link", { name: "Cursor" }).first().click(); await expect(page).toHaveURL(/\/docs\/integrations\/cursor/); await expect(page.locator(".docs-prose h1, .docs-prose h2").first()).toContainText( "Cursor", ); await expect(page.getByText("api.haiyushuke.com")).toBeVisible(); }); test("文档中心法律条款页可访问", async ({ page }) => { const agreement = await page.goto("/docs/legal/user-agreement", { waitUntil: "domcontentloaded", }); expect(agreement?.ok()).toBeTruthy(); await expect(page.locator(".docs-prose h1").first()).toContainText("用户协议"); await expect(page.locator(".docs-prose")).toContainText("服务说明"); const privacy = await page.goto("/docs/legal/privacy", { waitUntil: "domcontentloaded", }); expect(privacy?.ok()).toBeTruthy(); await expect(page.locator(".docs-prose h1").first()).toContainText("隐私政策"); }); test("全局样式编译通过(无 Turbopack CSS 报错页)", async ({ page }) => { await page.goto("/", { waitUntil: "domcontentloaded" }); const bodyText = await page.locator("body").innerText(); expect(bodyText).not.toContain("Cannot apply unknown utility class"); expect(bodyText).not.toContain("CssSyntaxError"); }); });