: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, render, screen } from '@testing-library/react'
import { useValues } from 'kea'
import { NativeEmailIntegrationChoice } from './EmailTemplater'
let mockSenderRotationEnabled = false
jest.mock('lib/hooks/useFeatureFlag', () => ({
useFeatureFlag: () => mockSenderRotationEnabled,
}))
jest.mock('kea', () => ({
...jest.requireActual('kea'),
useValues: jest.fn(),
}))
jest.mock('@posthog/lemon-ui', () => ({
...jest.requireActual('@posthog/lemon-ui'),
LemonInputSelect: () => <div data-attr="multiple-email-sender-select" />,
LemonSelect: () => <div data-attr="single-email-sender-select" />,
}))
describe('NativeEmailIntegrationChoice', () => {
afterEach(cleanup)
beforeEach(() => {
jest.mocked(useValues).mockReturnValue({
integrationsLoading: false,
integrations: [
{
id: 1,
kind: 'email',
display_name: 'Alice <[email protected]>',
},
{
id: 2,
kind: 'email',
display_name: 'Bob <[email protected]>',
},
],
})
})
it.each([
[false, 'single-email-sender-select'],
[true, 'multiple-email-sender-select'],
])('renders the expected sender picker when the rotation flag is %s', (flagEnabled, expectedPicker) => {
mockSenderRotationEnabled = flagEnabled
render(<NativeEmailIntegrationChoice label="From" value={{ integrationId: 1 }} onChange={jest.fn()} />)
expect(screen.getByTestId(expectedPicker)).toBeInTheDocument()
expect(screen.getByText('Custom sender')).toBeInTheDocument()
})
})