mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
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(
|
|
<InlineLink href={`${DOCS_URL}/guides/platform/regions`} onClick={onClick}>
|
|
specific region
|
|
</InlineLink>
|
|
)
|
|
|
|
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(
|
|
<InlineLink href={`${DOCS_URL}/guides/platform/regions`}>specific region</InlineLink>
|
|
)
|
|
|
|
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(<InlineLink href="https://github.com/supabase/supabase">GitHub</InlineLink>)
|
|
|
|
await user.click(screen.getByRole('link', { name: 'GitHub' }))
|
|
|
|
expect(track).not.toHaveBeenCalled()
|
|
})
|