Files
digital-psychology/apps/user-h5/src/pages/RelationPage.spec.ts
T
jackyu66gitandCursor 53eb4577b3 feat: 按测测功能重构 H5 首页与各子页,并修正顶栏「+」添加档案菜单
对齐测测交互:首页「+」支持邀请填档案/添加档案/邀请合盘;各 Tab 与工具页按同一视觉与功能标准落地;本地对照截图目录显式忽略。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-05 14:32:35 +08:00

93 lines
2.9 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { mount, flushPromises } from '@vue/test-utils'
import RelationPage from './RelationPage.vue'
const { api } = vi.hoisted(() => ({
api: {
listProfiles: vi.fn(),
createProfile: vi.fn(),
createRelationInsight: vi.fn(),
createOrder: vi.fn(),
payMock: vi.fn(),
getReport: vi.fn(),
},
}))
vi.mock('../api/client', () => ({ api }))
vi.mock('vue-router', () => ({
useRoute: () => ({ query: {} }),
useRouter: () => ({ back: vi.fn() }),
}))
describe('RelationPage', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('generates relation insight summary and gates tips', async () => {
api.listProfiles.mockResolvedValue({
items: [{ id: 'self1', relation: 'self', display_name: '我', birth_date: '1990-01-01' }],
})
api.createProfile.mockResolvedValue({ id: 'other1', relation: 'other' })
api.createRelationInsight.mockResolvedValue({
insight: { id: 'i1', report_id: 'rr1' },
report: {
id: 'rr1',
has_deep_access: false,
summary: {
me_style: '我·稳',
other_style: 'TA·活',
diff_one_liner: '节奏不同',
me_keywords: ['稳'],
other_keywords: ['活'],
},
detail: null,
},
})
const w = mount(RelationPage)
await w.findAll('button').find((b) => b.text().includes('去匹配'))!.trigger('click')
await flushPromises()
expect(w.text()).toContain('我·稳')
expect(w.text()).toContain('节奏不同')
expect(w.text()).toContain('解锁完整分析')
})
it('shows tips after deep_access pay', async () => {
api.listProfiles.mockResolvedValue({
items: [{ id: 'self1', relation: 'self', display_name: '我', birth_date: '1990-01-01' }],
})
api.createProfile.mockResolvedValue({ id: 'other1' })
api.createRelationInsight.mockResolvedValue({
insight: { id: 'i1' },
report: {
id: 'rr1',
has_deep_access: false,
summary: { me_style: 'A', other_style: 'B', diff_one_liner: 'D', me_keywords: [], other_keywords: [] },
detail: null,
},
})
api.createOrder.mockResolvedValue({ order_id: 'o1' })
api.payMock.mockResolvedValue({ paid: true })
api.getReport.mockResolvedValue({
id: 'rr1',
has_deep_access: true,
summary: { me_style: 'A', other_style: 'B', diff_one_liner: 'D', me_keywords: [], other_keywords: [] },
detail: {
communication: ['先倾听'],
interaction: ['留白'],
maintenance: ['定期沟通'],
},
})
const w = mount(RelationPage)
await w.findAll('button').find((b) => b.text().includes('去匹配'))!.trigger('click')
await flushPromises()
await w.findAll('button').find((b) => b.text().includes('解锁完整分析'))!.trigger('click')
await flushPromises()
expect(w.text()).toContain('可执行建议')
expect(w.text()).toContain('先倾听')
})
})