Skip to content

: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.

fix(toolbar): let a second web experiment transformation open (#95268)

posthog[bot]b90364966a66
diff --git a/frontend/src/toolbar/experiments/WebExperimentVariant.test.tsx b/frontend/src/toolbar/experiments/WebExperimentVariant.test.tsx
new file mode 100644
index 000000000000..5d06d7aada8c
--- /dev/null
+++ b/frontend/src/toolbar/experiments/WebExperimentVariant.test.tsx
@@ -0,0 +1,46 @@
+import '@testing-library/jest-dom'
+
+import { render, screen, within } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+
+import { initKeaTests } from '~/test/init'
+import { experimentsTabLogic } from '~/toolbar/experiments/experimentsTabLogic'
+import { WebExperimentVariant } from '~/toolbar/experiments/WebExperimentVariant'
+import { toolbarConfigLogic } from '~/toolbar/toolbarConfigLogic'
+
+describe('WebExperimentVariant', () => {
+ const setVariantTransforms = (selectors: string[]): void => {
+ experimentsTabLogic.actions.setExperimentFormValue('variants', {
+ test: { transforms: selectors.map((selector) => ({ selector })), rollout_percentage: 100 },
+ })
+ }
+
+ beforeEach(() => {
+ // The toolbar calls `global.fetch` directly, and mounting the tab logic loads the experiment list
+ global.fetch = jest.fn(() =>
+ Promise.resolve({ ok: true, json: () => Promise.resolve({ results: [] }) } as any as Response)
+ )
+ initKeaTests()
+ toolbarConfigLogic.build({ apiURL: 'http://localhost', accessToken: 'test-token' }).mount()
+ experimentsTabLogic().mount()
+ })
+
+ it('opens the only transformation on mount', () => {
+ setVariantTransforms(['.headline'])
+
+ render(<WebExperimentVariant variant="test" />)
+
+ expect(screen.getByText('Select element')).toBeInTheDocument()
+ })
+
+ it('lets you open a later transformation once the variant has several', async () => {
+ setVariantTransforms(['.headline', '.subtitle'])
+
+ render(<WebExperimentVariant variant="test" />)
+ await userEvent.click(screen.getByText('.subtitle'))
+
+ const secondPanel = screen.getByText('.subtitle').closest('.LemonCollapsePanel') as HTMLElement
+ expect(secondPanel).toHaveAttribute('aria-expanded', 'true')
+ expect(within(secondPanel).getByText('Select element')).toBeInTheDocument()
+ })
+})
diff --git a/frontend/src/toolbar/experiments/WebExperimentVariant.tsx b/frontend/src/toolbar/experiments/WebExperimentVariant.tsx
index 449f5f730af6..1da655e08ae5 100644
--- a/frontend/src/toolbar/experiments/WebExperimentVariant.tsx
+++ b/frontend/src/toolbar/experiments/WebExperimentVariant.tsx
@@ -67,7 +67,7 @@ export function WebExperimentVariant({ variant }: WebExperimentVariantProps): JS
experimentForm?.variants[variant].transforms?.length > 0 ? (
<LemonCollapse
size="small"
- activeKey={experimentForm?.variants[variant].transforms.length === 1 ? 0 : undefined}
+ defaultActiveKey={experimentForm?.variants[variant].transforms.length === 1 ? 0 : undefined}
panels={experimentForm?.variants[variant].transforms.map((transform, transformIndex) => {
return {
key: transformIndex,