Files
digital-psychology/apps/user-h5/e2e/p2-explore-paths.spec.ts
T
jackyu66gitandCursor 69fa1b85d6 fix(ECR-001): 对齐 Playwright e2e 与 /psy/ base 及现 UI
E2E 改走 /psy 路径并更新过时文案断言,恢复 L3 冒烟;补充 Phase F QA 报告。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-05 18:34:11 +08:00

107 lines
3.5 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('/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: 'Hi,我是愈心 AI' })).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()
})