Files
supabase/apps/studio/components/ui/DocsButton.test.tsx
K-Dog (Kevin) 27c4433a3e feat: revised project add-ons page (#54186)
The current add-ons page only lists a subset of available add-ons, which
often causes confusion with things like Advanced MFA Auth (customers
cant find where to configure it).

The revised add-on page covers all potentially configured project
add-ons including replicas and advanced disk. This should help the
customer locate configured add-ons and at the same time discover
potentially interesting add-ons. This can be enhanced further in the
future with "smart" suggestions based on usage.
2026-11-30 21:54:44 +08:00

61 lines
2.0 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 { 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 topic', async () => {
const user = userEvent.setup()
customRender(<DocsButton href="https://supabase.com/docs/guides/auth" topic="Auth" />)
await user.click(screen.getByRole('link', { name: /auth documentation/i }))
expect(track).toHaveBeenCalledTimes(1)
expect(track).toHaveBeenCalledWith('docs_button_clicked', { topic: 'Auth' })
})
test('clicking without a topic omits the topic property', async () => {
const user = userEvent.setup()
customRender(<DocsButton href="https://supabase.com/docs/guides/auth" />)
await user.click(screen.getByRole('link', { name: 'Docs' }))
expect(track).toHaveBeenCalledTimes(1)
expect(track).toHaveBeenCalledWith('docs_button_clicked', {})
})
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="https://supabase.com/docs/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('docs_button_clicked', { topic: 'Auth' })
})