83 行
2.7 KiB
TypeScript
83 行
2.7 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
import { EMPLOYEE, login } from "./helpers/auth";
|
|
|
|
function mockWecomConfigPayload() {
|
|
return {
|
|
enabled: true,
|
|
entryEnabled: true,
|
|
oauthEnabled: true,
|
|
corpId: "wx-test-corp",
|
|
agentId: "1000001",
|
|
loginUrl: "/api/auth/wecom/login?returnTo=%2Fportal",
|
|
bindEnabled: true,
|
|
defaultReturnTo: "/portal",
|
|
status: "ready",
|
|
statusReasons: [],
|
|
};
|
|
}
|
|
|
|
test("E2E 企微入口:普通浏览器下企微按钮为次级入口", async ({ page }) => {
|
|
await page.route("**/api/auth/wecom/config", async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({
|
|
requestId: "mock-wecom-config",
|
|
data: mockWecomConfigPayload(),
|
|
}),
|
|
});
|
|
});
|
|
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");
|
|
await expect(page.getByTestId("login-password-primary-panel")).toBeVisible();
|
|
await expect(page.getByTestId("wecom-entry-secondary")).toBeVisible();
|
|
|
|
await page.getByTestId("wecom-entry-secondary").click();
|
|
await expect(page).toHaveURL(/\/api\/auth\/wecom\/login\?returnTo=/);
|
|
|
|
await login(page, EMPLOYEE);
|
|
await page.goto("/settings/profile");
|
|
await expect(page.getByRole("heading", { name: "企业微信绑定" })).toBeVisible();
|
|
await expect(page.getByText("接入状态", { exact: true })).toBeVisible();
|
|
});
|
|
|
|
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 page.route("**/api/auth/wecom/config", async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({
|
|
requestId: "mock-wecom-config",
|
|
data: mockWecomConfigPayload(),
|
|
}),
|
|
});
|
|
});
|
|
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=unbound");
|
|
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-password-secondary-panel")).toBeVisible();
|
|
});
|