: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 } from '@testing-library/react'
import { BindLogic, Provider } from 'kea'
import { FEATURE_FLAGS } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { Experiment, ExperimentStatus } from '~/types'
import { NEW_EXPERIMENT } from 'products/experiments/frontend/constants'
import { experimentLogic } from '../experimentLogic'
import { ExperimentWarningBanner } from './ExperimentWarningBanners'
const EXPERIMENT_ID = 7
describe('ExperimentWarningBanner', () => {
let logic: ReturnType<typeof experimentLogic.build>
beforeEach(() => {
const emptyList = { count: 0, next: null, previous: null, results: [] }
useMocks({
get: {
'/api/projects/:team/experiments': emptyList,
'/api/projects/:team/experiment_holdouts': emptyList,
'/api/projects/:team/experiment_saved_metrics': emptyList,
},
})
initKeaTests()
featureFlagLogic.mount()
featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.EXPERIMENT_HEALTH_FINDINGS], {
[FEATURE_FLAGS.EXPERIMENT_HEALTH_FINDINGS]: true,
})
logic = experimentLogic({ experimentId: EXPERIMENT_ID })
logic.mount()
})
afterEach(() => {
cleanup()
logic.unmount()
})
it.each([
{ variantKey: 'test', expected: 'Variant "test" is rolled out to 100% of users.' },
{ variantKey: null, expected: 'One variant is rolled out to 100% of users.' },
])('names the shipped variant $variantKey', ({ variantKey, expected }) => {
logic.actions.setExperiment({
...NEW_EXPERIMENT,
id: EXPERIMENT_ID,
status: ExperimentStatus.Running,
start_date: dayjs().subtract(3, 'day').toISOString(),
feature_flag: { id: 1, key: 'checkout-flag', active: true, filters: { groups: [] } },
} as unknown as Experiment)
logic.actions.loadExperimentHealthSuccess({
findings: [
{
code: 'variant_shipped_while_running',
subcode: 'running_but_single_variant_shipped',
reason: null,
severity: 'warning',
title: '',
detail: '',
check: 'flag_state',
evidence: { variant_key: variantKey },
actions: [],
diagnostic_ref: null,
},
],
checks: [],
})
const { container } = render(
<Provider>
<BindLogic logic={experimentLogic} props={{ experimentId: EXPERIMENT_ID }}>
<ExperimentWarningBanner />
</BindLogic>
</Provider>
)
expect(container).toHaveTextContent(expected)
})
})