:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import '@testing-library/jest-dom'
import { cleanup, fireEvent, render } from '@testing-library/react'
import posthog from 'posthog-js'
import { initKeaTests } from '~/test/init'
import { SceneTitlePanelButton } from './SceneTitlePanelButton'
describe('SceneTitlePanelButton', () => {
beforeEach(() => {
initKeaTests()
jest.spyOn(posthog, 'capture').mockImplementation(() => undefined as any)
})
afterEach(() => {
cleanup()
jest.restoreAllMocks()
})
// Without this event a click that never reaches `openSidePanel` leaves no trace at all,
// so the panel-never-opens failure has no denominator.
test('captures a click on the PostHog AI button', () => {
render(<SceneTitlePanelButton />)
fireEvent.click(document.querySelector('[data-attr="open-context-panel-ai-button"]') as HTMLElement)
expect(posthog.capture).toHaveBeenCalledWith('scene ai button clicked', expect.objectContaining({ tool: null }))
})
})