Files
digital-psychology/apps/user-h5/src/pages/RelationPage.spec.ts
T
jackyu66gitandCursor 5ceb3ce749
ci / h5 (push) Canceled after 0s
ci / api (push) Canceled after 0s
ci / ess-docs (push) Canceled after 0s
feat(ECR-010): Ops-E 系统运营;修复登出解绑;P2 Complete
落地管理员 RBAC/封禁/推送任务 stub,logout 解绑 device 并统一各页 ensureAccount,同时收口 P2 生日生成与状态文档。

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

95 lines
3.0 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: {
authMe: vi.fn(),
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: {}, fullPath: '/relation' }),
useRouter: () => ({ back: vi.fn(), replace: vi.fn() }),
}))
describe('RelationPage', () => {
beforeEach(() => {
vi.clearAllMocks()
api.authMe.mockResolvedValue({ id: 'u1' })
})
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('先倾听')
})
})