import { describe, it, expect, vi, beforeEach } from 'vitest' import { mount, flushPromises } from '@vue/test-utils' import LifeRhythmPage from './LifeRhythmPage.vue' const { api } = vi.hoisted(() => ({ api: { authMe: vi.fn(), listProfiles: vi.fn(), getLatestReport: vi.fn(), createProfile: vi.fn(), createRhythm: vi.fn(), getReport: vi.fn(), createOrder: vi.fn(), payMock: vi.fn(), }, })) vi.mock('../api/client', () => ({ api })) vi.mock('vue-router', () => ({ useRoute: () => ({ query: { y: '1992', m: '6', d: '8' }, fullPath: '/rhythm' }), useRouter: () => ({ back: vi.fn(), replace: vi.fn() }), })) describe('LifeRhythmPage', () => { beforeEach(() => { vi.clearAllMocks() api.authMe.mockResolvedValue({ id: 'u1' }) api.listProfiles.mockResolvedValue({ items: [] }) }) it('creates rhythm report from birth query', async () => { api.createProfile.mockResolvedValue({ id: 'p1' }) api.createRhythm.mockResolvedValue({ id: 'r-rhythm', type: 'rhythm', has_deep_access: false, summary: { headline: '节律标题', one_liner: '节律一句' }, detail: null, }) const w = mount(LifeRhythmPage) await flushPromises() expect(api.createRhythm).toHaveBeenCalledWith('p1') expect(w.text()).toContain('节律标题') expect(w.text()).toContain('节气陪伴') }) })