落地 synastry/star/ask API 与 H5 页面,补齐 cece-frontend-re complete-design 证据文档,并加入 Android 模拟器截图抓取脚本。 Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { AnalyticsEvent, track, trackPageView } from './analytics'
|
|
|
|
describe('analytics.track', () => {
|
|
beforeEach(() => {
|
|
window.gtag = vi.fn()
|
|
})
|
|
afterEach(() => {
|
|
delete window.gtag
|
|
})
|
|
|
|
it('calls gtag with event name and params', () => {
|
|
track(AnalyticsEvent.HomeCtaPortrait)
|
|
expect(window.gtag).toHaveBeenCalledWith('event', 'home_cta_portrait', {})
|
|
})
|
|
|
|
it('omits undefined params', () => {
|
|
track(AnalyticsEvent.PortraitCompleted, { source: 'query', report_id: undefined })
|
|
expect(window.gtag).toHaveBeenCalledWith('event', 'portrait_completed', { source: 'query' })
|
|
})
|
|
|
|
it('does not throw when gtag missing', () => {
|
|
delete window.gtag
|
|
expect(() => track(AnalyticsEvent.RelationCompleted)).not.toThrow()
|
|
})
|
|
|
|
it('trackPageView sends page_path', () => {
|
|
trackPageView('/portrait', '个人画像')
|
|
expect(window.gtag).toHaveBeenCalledWith('event', 'page_view', {
|
|
page_path: '/portrait',
|
|
page_title: '个人画像',
|
|
})
|
|
})
|
|
})
|