Files
digital-psychology/apps/user-h5/e2e/p2-explore-paths.spec.ts
T
jackyu66gitandCursor 89756f65b4 feat(ECR-012–016): 合规、题库、时辰刷新、头像、MBTI OEJTS 与埋点
落地输入合规、探索题库、报告日/时辰刷新、账号头像、OEJTS 量表,并补齐 H5 埋点与 Admin 漏斗;同步 ESS 工件、切至自建 Git、清理 GitHub Actions。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-13 01:27:58 +08:00

116 lines
3.8 KiB
TypeScript

import { test, expect } from '@playwright/test'
function ok(data: unknown) {
return {
status: 200,
contentType: 'application/json',
body: JSON.stringify({ code: 0, message: 'success', data }),
headers: { 'X-Device-Key': 'e2e-device' },
}
}
test('star / rhythm / cards pages render with mocked API', async ({ page }) => {
await page.route('**/api/v1/**', async (route) => {
const url = route.request().url()
const method = route.request().method()
if (url.includes('/auth/me')) {
await route.fulfill(ok({ id: 'u1', phone: '13800000000' }))
return
}
if (url.includes('/profiles') && method === 'GET') {
await route.fulfill(ok({ items: [] }))
return
}
if (url.includes('/profiles') && method === 'POST') {
await route.fulfill(ok({
id: 'prof-e2e',
user_id: 'u1',
relation: 'self',
display_name: '我',
birth_date: '1983-06-06',
created_at: new Date().toISOString(),
}))
return
}
if (url.includes('/reports/star') && method === 'POST') {
await route.fulfill(ok({
id: 'rep-star',
type: 'star',
has_deep_access: false,
summary: { headline: 'E2E星象', one_liner: '星象摘要', keywords: ['灵活'] },
detail: null,
created_at: new Date().toISOString(),
}))
return
}
if (url.includes('/reports/rhythm') && method === 'POST') {
await route.fulfill(ok({
id: 'rep-rhythm',
type: 'rhythm',
has_deep_access: false,
summary: { headline: 'E2E节律', one_liner: '节律摘要' },
detail: null,
created_at: new Date().toISOString(),
}))
return
}
if (url.includes('/image-cards/scenes')) {
await route.fulfill(ok({ items: [{ key: '情绪整理', label: '情绪整理' }] }))
return
}
if (url.includes('/image-cards/quota')) {
await route.fulfill(ok({ remaining: 3, daily_free: 3, unlimited: false }))
return
}
if (url.includes('/image-cards/draw') && method === 'POST') {
await route.fulfill(ok({
scene: '情绪整理',
quota_left: 2,
cards: [{
id: 'c01', title: 'E2E卡片', imagery: '意象', prompt: '反思?', tip: '一小步',
}],
report: {
id: 'rep-card',
type: 'image_card',
has_deep_access: false,
summary: { headline: '意象探索' },
detail: null,
},
}))
return
}
if (url.includes('/solar-terms/today')) {
await route.fulfill(ok({ name: '立秋', tip: '收敛节奏', date: '2026-08-02' }))
return
}
if (url.includes('/moods/today')) {
await route.fulfill(ok({ mood: null }))
return
}
await route.fulfill(ok({}))
})
await page.goto('/psy/star?y=1983&m=6&d=6')
await expect(page.getByText('E2E星象')).toBeVisible()
await expect(page.getByRole('button', { name: /解锁完整分析/ })).toBeVisible()
await page.goto('/psy/rhythm?y=1992&m=6&d=8')
await expect(page.getByText('身心节律').first()).toBeVisible()
await expect(page.getByText('E2E节律')).toBeVisible()
await page.goto('/psy/cards')
await expect(page.getByRole('heading', { name: '意象卡片' })).toBeVisible()
await expect(page.getByText('投射整理 · 自我反思')).toBeVisible()
await page.getByRole('button', { name: '关联生日' }).click()
await page.locator('input[type="number"]').nth(0).fill('1990')
await page.locator('input[type="number"]').nth(1).fill('5')
await page.locator('input[type="number"]').nth(2).fill('12')
await page.getByRole('button', { name: '抽取卡片' }).click()
await expect(page.getByText('E2E卡片')).toBeVisible()
await page.goto('/psy/companion')
await expect(page.getByText('立秋')).toBeVisible()
await expect(page.getByText('今日心情')).toBeVisible()
})