dify/web/app/components/step-by-step-tour/__tests__/analytics.spec.ts
Jingyi cb64446fa3
feat(web): add step-by-step tour shell (#38785)
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
2026-07-20 09:23:25 +00:00

40 lines
1.0 KiB
TypeScript

import { trackStepByStepTourEvent } from '../analytics'
const mockTrackEvent = vi.hoisted(() => vi.fn())
vi.mock('@/app/components/base/amplitude', () => ({
trackEvent: mockTrackEvent,
}))
describe('step-by-step tour analytics', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('tracks the unified event with scalar properties only', () => {
trackStepByStepTourEvent({
action: 'task_completed',
completed_task_count: 1,
home_outcome: 'lesson_app_created',
permission_variant: 'full',
task_id: 'home',
task_total: 4,
})
expect(mockTrackEvent).toHaveBeenCalledWith('step_tour', {
action: 'task_completed',
completed_task_count: 1,
home_outcome: 'lesson_app_created',
permission_variant: 'full',
task_id: 'home',
task_total: 4,
})
})
it('omits undefined optional properties', () => {
trackStepByStepTourEvent({ action: 'tour_enabled' })
expect(mockTrackEvent).toHaveBeenCalledWith('step_tour', { action: 'tour_enabled' })
})
})