import { describe, it, expect, vi, beforeEach } from 'vitest' import { mount, flushPromises } from '@vue/test-utils' import StarProfilePage from './StarProfilePage.vue' const { api, routeQuery } = vi.hoisted(() => ({ api: { authMe: vi.fn(), listProfiles: vi.fn(), createProfile: vi.fn(), createStar: vi.fn(), getLatestReport: vi.fn(), getReport: vi.fn(), createOrder: vi.fn(), payMock: vi.fn(), }, routeQuery: { y: '1990', m: '5', d: '12' } as Record, })) vi.mock('../api/client', () => ({ api })) vi.mock('vue-router', () => ({ useRoute: () => ({ query: routeQuery, fullPath: '/star?y=1990&m=5&d=12' }), useRouter: () => ({ back: vi.fn(), replace: vi.fn(), push: vi.fn() }), })) const summary = { headline: '小愈的星座更偏「稳健沉淀者」', one_liner: '一句', sign_cards: [{ key: 'sun', title: '太阳', label: '金牛', teaser: 't', element: '土', modality: '固定' }], chart: { note: '热带黄道', asc_lon: 120, houses: [{ num: 1, sign: '狮子' }] }, planets: [ { key: 'sun', title: '太阳', sign: '金牛', degree: '10.0°', house: 1, lon: 40, element: '土', modality: '固定' }, { key: 'moon', title: '月亮', sign: '巨蟹', degree: '5.0°', house: 2, lon: 95, element: '水', modality: '开创' }, { key: 'rise', title: '上升', sign: '狮子', degree: '0.0°', house: 1, lon: 120, element: '火', modality: '固定' }, ], aspects_preview: [{ a: 'sun', b: 'moon', type: 'square', orb: 2, label: '太阳刑相月亮(容许2.0°)', a_title: '太阳', b_title: '月亮' }], outlook: { daily: { title: '今日运势', label: '顺畅', score: 80, tip: 'tip', focus: '行动', boost: '红', caution: '慢', dims: { love: 1, career: 2, money: 3, mood: 4 } }, lifetime: { title: '一生运势摘要', label: '平稳', score: 70, tip: '人生阶段', focus: '人生阶段', boost: 'x', caution: 'y', dims: {} }, transits: [{ key: 't1', title: '行运太阳×本命太阳', aspect: '合相', tip: '推进' }], }, transits: [{ key: 't1', title: '行运太阳×本命太阳', aspect: '合相', tip: '推进' }], keywords: ['金牛'], } const starReport = { id: 'r1', type: 'star', has_deep_access: false, summary, detail: null, } describe('StarProfilePage', () => { beforeEach(() => { vi.clearAllMocks() api.authMe.mockResolvedValue({ id: 'u1' }) api.listProfiles.mockResolvedValue({ items: [] }) api.createProfile.mockResolvedValue({ id: 'p1' }) api.getLatestReport.mockResolvedValue(starReport) api.createStar.mockResolvedValue(starReport) }) it('shows natal wheel and free chart content', async () => { const w = mount(StarProfilePage, { global: { stubs: { RouterLink: true } } }) await flushPromises() expect(api.createProfile).toHaveBeenCalled() expect(api.getLatestReport).toHaveBeenCalledWith('p1', 'star') await w.findAll('button').find((b) => b.text() === '星盘')!.trigger('click') await flushPromises() expect(w.find('svg.wheel').exists()).toBe(true) expect(w.text()).toContain('相位速览') expect(w.text()).toContain('太阳刑相月亮') }) it('shows daily and lifetime fortune tabs', async () => { const w = mount(StarProfilePage, { global: { stubs: { RouterLink: true } } }) await flushPromises() await w.findAll('button').find((b) => b.text() === '运势')!.trigger('click') await flushPromises() expect(w.text()).toContain('今日运势') expect(w.text()).toContain('焦点:行动') await w.findAll('button').find((b) => b.text() === '一生')!.trigger('click') await flushPromises() expect(w.text()).toContain('一生运势摘要') }) })