import { screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { beforeEach, expect, test, vi } from 'vitest' import { InlineLink } from './InlineLink' import { DOCS_URL } from '@/lib/constants' import { customRender } from '@/tests/lib/custom-render' const { track } = vi.hoisted(() => ({ track: vi.fn() })) vi.mock('@/lib/telemetry/track', () => ({ useTrack: () => track })) beforeEach(() => { track.mockClear() }) test('clicking a docs link tracks the docs path and still runs the caller onClick', async () => { const user = userEvent.setup() const onClick = vi.fn() customRender( specific region ) await user.click(screen.getByRole('link', { name: 'specific region' })) expect(track).toHaveBeenCalledTimes(1) expect(track).toHaveBeenCalledWith('studio_docs_link_clicked', { docsPath: '/guides/platform/regions', }) expect(onClick).toHaveBeenCalledTimes(1) }) test('middle-clicking a docs link tracks the docs path', async () => { const user = userEvent.setup() customRender( specific region ) await user.pointer({ keys: '[MouseMiddle]', target: screen.getByRole('link', { name: 'specific region' }), }) expect(track).toHaveBeenCalledTimes(1) expect(track).toHaveBeenCalledWith('studio_docs_link_clicked', { docsPath: '/guides/platform/regions', }) }) test('clicking an external link outside the docs tracks nothing', async () => { const user = userEvent.setup() customRender(GitHub) await user.click(screen.getByRole('link', { name: 'GitHub' })) expect(track).not.toHaveBeenCalled() })