mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 23:49:03 +00:00
56 lines
1.8 KiB
TypeScript
56 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 { DocsButton } from './DocsButton'
|
|
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 tracks once with the docs path and never the topic', async () => {
|
|
const user = userEvent.setup()
|
|
customRender(
|
|
<DocsButton href={`${DOCS_URL}/guides/auth?queryGroups=flow#redirect-urls`} topic="Auth" />
|
|
)
|
|
|
|
await user.click(screen.getByRole('link', { name: /auth documentation/i }))
|
|
|
|
expect(track).toHaveBeenCalledTimes(1)
|
|
expect(track).toHaveBeenCalledWith('studio_docs_link_clicked', {
|
|
docsPath: '/guides/auth#redirect-urls',
|
|
})
|
|
})
|
|
|
|
test('clicking does not bubble to a clickable parent', async () => {
|
|
const user = userEvent.setup()
|
|
const onParentClick = vi.fn()
|
|
customRender(
|
|
<div onClick={onParentClick}>
|
|
<DocsButton href="https://supabase.com/docs/guides/auth" />
|
|
</div>
|
|
)
|
|
|
|
await user.click(screen.getByRole('link', { name: 'Docs' }))
|
|
|
|
expect(onParentClick).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('icon-only keeps the topic in the accessible name and still tracks clicks', async () => {
|
|
const user = userEvent.setup()
|
|
customRender(<DocsButton iconOnly href={`${DOCS_URL}/guides/auth`} topic="Auth" />)
|
|
|
|
const link = screen.getByRole('link', { name: 'Auth documentation (opens in new tab)' })
|
|
expect(link).not.toHaveTextContent('Docs')
|
|
|
|
await user.click(link)
|
|
|
|
expect(track).toHaveBeenCalledWith('studio_docs_link_clicked', { docsPath: '/guides/auth' })
|
|
})
|