import { expect, test } from "@playwright/test"; function mockWecomConfigPayload() { return { enabled: true, entryEnabled: true, oauthEnabled: true, corpId: "wx-test-corp", agentId: "1000001", loginUrl: "/api/auth/wecom/login?returnTo=%2Fmobile", bindEnabled: true, defaultReturnTo: "/mobile", status: "ready", statusReasons: [], }; } function envelope(data: unknown) { return { requestId: "mock-request", data, }; } async function mockAuthBase(page: import("@playwright/test").Page) { await page.route("**/api/auth/capabilities", async (route) => { await route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(envelope({ emailDelivery: { ready: true, statusReasons: [] }, emailLoginCode: { enabled: true }, passwordReset: { enabled: true }, })), }); }); await page.route("**/api/auth/sso/providers", async (route) => { await route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(envelope([])), }); }); } async function mockWecomConfig(page: import("@playwright/test").Page) { await page.route("**/api/auth/wecom/config", async (route) => { await route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(envelope(mockWecomConfigPayload())), }); }); } test("E2E 企微入口:普通浏览器下只提示企业微信工作台打开", async ({ page }) => { await mockAuthBase(page); await mockWecomConfig(page); await page.goto("/login"); await expect(page.getByTestId("login-password-primary-panel")).toBeVisible(); await expect(page.getByTestId("wecom-entry-browser-notice")).toContainText("请从企业微信工作台打开 OA"); await expect(page.getByTestId("wecom-entry-secondary")).toHaveCount(0); }); test("E2E 企微入口:企业微信场景优先显示企微 CTA,并展示映射缺失提示", async ({ page }) => { await page.addInitScript(() => { Object.defineProperty(window.navigator, "userAgent", { configurable: true, value: "Mozilla/5.0 wxwork/4.1.20 MicroMessenger/7.0.1", }); }); await mockAuthBase(page); await mockWecomConfig(page); await page.route("**/api/auth/wecom/login?**", async (route) => { await route.fulfill({ status: 200, contentType: "text/plain", body: "mock wecom login entry", }); }); await page.goto("/login?redirect=%2Fportal&wecom=account_mapping_required"); await expect(page.getByTestId("login-wecom-primary-panel")).toBeVisible(); await expect(page.getByTestId("wecom-entry-primary")).toBeVisible(); await expect(page.getByTestId("login-wecom-notice")).toContainText("企业微信账号映射尚未完成"); await expect(page.getByTestId("login-wecom-notice")).not.toContainText("账号密码登录"); await expect(page.getByTestId("login-password-secondary-panel")).toBeVisible(); });