Files
huike-e2e-moicen/tests/logged-in-and-isolation.spec.ts
T
weli 1e7337c239 test: guest onboarding, logged-in isolation, optional real_name
Add guest-onboarding and logged-in-and-isolation specs; remove moicen-unionid-chain;
MOICEN_E2E_EXPECTED_REAL_NAME for 欢迎回来+姓名; CI secret; workers=1; longer goto timeouts.

Made-with: Cursor
2026-04-26 17:22:41 +08:00

82 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect } from '@playwright/test';
const moicenUnionid = process.env.MOICEN_E2E_UNIONID?.trim();
const expectedRealName = process.env.MOICEN_E2E_EXPECTED_REAL_NAME?.trim();
test.describe('已登录用户与串号防护', () => {
test.skip(!moicenUnionid, '需要 MOICEN_E2E_UNIONIDSecret 或 .env.e2e');
test('login2_with_unionid 后不应停留在未登录占位,应出现身份或工作台', async ({
page,
}) => {
const q = new URLSearchParams({
unionid: moicenUnionid!,
status: '2',
});
await page.goto(`/?${q.toString()}`, {
waitUntil: 'domcontentloaded',
timeout: 60_000,
});
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
await expect(
page.getByText('请返回微信小程序完成登录')
).not.toBeVisible({ timeout: 90_000 });
await expect(
page.getByText(/请选择您的登录身份|欢迎回来|进入工作台/)
).toBeVisible({ timeout: 90_000 });
});
test('已登录后 URL 中异主 unionid 应被剥离(不串号)', async ({ page }) => {
const q = new URLSearchParams({
unionid: moicenUnionid!,
status: '2',
});
await page.goto(`/?${q.toString()}`, {
waitUntil: 'domcontentloaded',
timeout: 60_000,
});
await expect(
page.getByText(/请选择您的登录身份|欢迎回来|进入工作台/)
).toBeVisible({ timeout: 90_000 });
const poisonUnionid = 'e2eStrangerUnionidNotCurrentUser001';
const pathBefore = new URL(page.url()).pathname || '/';
await page.goto(
`${pathBefore}?unionid=${encodeURIComponent(poisonUnionid)}&status=2`,
{ waitUntil: 'domcontentloaded', timeout: 60_000 }
);
await page.waitForURL(
(u) => !u.toString().includes(poisonUnionid),
{ timeout: 45_000 }
);
expect(page.url()).not.toContain(poisonUnionid);
await expect(
page.getByText('请返回微信小程序完成登录')
).not.toBeVisible();
});
test('可选:工作台「欢迎回来」展示配置的真实姓名(自己的数据)', async ({
page,
}) => {
test.skip(
!expectedRealName,
'未设置 MOICEN_E2E_EXPECTED_REAL_NAME 时跳过(与库中 real_name 一致,如 阿难)'
);
const q = new URLSearchParams({
unionid: moicenUnionid!,
status: '2',
});
await page.goto(`/?${q.toString()}`, {
waitUntil: 'domcontentloaded',
timeout: 60_000,
});
if (await page.getByText('请选择您的登录身份').isVisible().catch(() => false)) {
await page.locator('.van-grid-item').first().click();
}
await expect(page.getByText('欢迎回来')).toBeVisible({ timeout: 120_000 });
await expect(page.getByText(expectedRealName!)).toBeVisible({
timeout: 30_000,
});
});
});