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.

chore(insights): dedupe playwright insight specs (#62858)

Sam Pennington775a9a06a4ee
diff --git a/playwright/e2e/product-analytics/insight-creation.spec.ts b/playwright/e2e/product-analytics/insight-creation.spec.ts
deleted file mode 100644
index f5eb96f4429e..000000000000
--- a/playwright/e2e/product-analytics/insight-creation.spec.ts
+++ /dev/null
@@ -1,141 +0,0 @@
-import { InsightType } from '~/types'
-
-import { DashboardPage } from '../../page-models/dashboardPage'
-import { InsightPage } from '../../page-models/insightPage'
-import { PlaywrightWorkspaceSetupResult, expect, test } from '../../utils/workspace-test-base'
-
-test.describe('Insight creation', () => {
- let workspace: PlaywrightWorkspaceSetupResult | null = null
-
- test.beforeAll(async ({ playwrightSetup }) => {
- workspace = await playwrightSetup.createWorkspace({ use_current_time: true, skip_onboarding: true })
- })
-
- test.beforeEach(async ({ page, playwrightSetup }) => {
- await playwrightSetup.login(page, workspace!)
- })
-
- test('Retention: verify table and chart render, save and persist', async ({ page }) => {
- const insight = new InsightPage(page)
-
- await test.step('navigate to new Retention insight and verify active tab', async () => {
- await insight.goToNewInsight(InsightType.RETENTION)
- await expect(insight.activeTab).toContainText('Retention')
- await insight.retention.waitForChart()
- })
-
- await test.step('verify retention table renders with cohort rows', async () => {
- const rows = insight.retention.table.locator('tr')
- const rowCount = await rows.count()
- expect(rowCount).toBeGreaterThanOrEqual(1)
- })
-
- await test.step('save and verify view mode', async () => {
- await insight.save()
- await expect(insight.editButton).toBeVisible()
- })
- })
-
- test('Paths: verify page renders, save and persist', async ({ page }) => {
- const insight = new InsightPage(page)
-
- await test.step('navigate to new Paths insight and verify active tab', async () => {
- await insight.goToNewInsight(InsightType.PATHS)
- await expect(insight.activeTab).toContainText('Paths')
- await insight.paths.waitForChart()
- })
-
- await test.step('save and verify view mode', async () => {
- await insight.save()
- await expect(insight.editButton).toBeVisible()
- })
- })
-
- test('Stickiness: verify chart and save', async ({ page }) => {
- const insight = new InsightPage(page)
-
- await test.step('navigate to new Stickiness insight and wait for result', async () => {
- await insight.goToNewInsight(InsightType.STICKINESS)
- await expect(insight.activeTab).toContainText('Stickiness')
- await insight.stickiness.waitForChart()
- })
-
- await test.step('verify details table', async () => {
- await insight.stickiness.waitForDetailsTable()
- const tableText = await insight.stickiness.detailsTable.textContent()
- expect(tableText?.toLowerCase()).toContain('day')
- })
-
- await test.step('save and verify view mode', async () => {
- await insight.save()
- await expect(insight.editButton).toBeVisible()
- })
- })
-
- test('Lifecycle: verify chart and lifecycle toggles, save and persist', async ({ page }) => {
- const insight = new InsightPage(page)
-
- await test.step('navigate to new Lifecycle insight and wait for result', async () => {
- await insight.goToNewInsight(InsightType.LIFECYCLE)
- await expect(insight.activeTab).toContainText('Lifecycle')
- await insight.lifecycle.waitForChart()
- })
-
- await test.step('verify lifecycle toggles section is present', async () => {
- await expect(page.getByText('Lifecycle Toggles')).toBeVisible()
- })
-
- await test.step('save and verify view mode', async () => {
- await insight.save()
- await expect(insight.editButton).toBeVisible()
- })
- })
-
- test('SQL / HogQL: write query, execute and verify results', async ({ page }) => {
- const insight = new InsightPage(page)
-
- await test.step('navigate to SQL editor and verify it renders', async () => {
- await insight.goToSql()
- await insight.sql.waitForChart()
- })
-
- await test.step('write and execute a HogQL query', async () => {
- await insight.sql.writeQuery(
- [
- 'SELECT',
- ' count() AS total_pageviews,',
- ' toDate(timestamp) AS day',
- 'FROM events',
- "WHERE event = '$pageview'",
- 'GROUP BY day',
- 'ORDER BY day DESC',
- 'LIMIT 10',
- ].join('\n')
- )
- await insight.sql.run()
- })
-
- await test.step('verify results appear', async () => {
- await expect(page.getByText('Showing 10 rows')).toBeVisible()
- await expect(page.getByText('total_pageviews').first()).toBeVisible()
- })
- })
-
- test('Save to Dashboard: create Trends insight and add to a new dashboard', async ({ page }) => {
- const insight = new InsightPage(page)
- const dashboard = new DashboardPage(page)
-
- await test.step('create and save a Trends insight', async () => {
- await insight.goToNewTrends()
- await insight.trends.waitForChart()
- await insight.save()
- await expect(insight.editButton).toBeVisible()
- })
-
- await test.step('add insight to a new dashboard', async () => {
- await dashboard.addToNewDashboardFromInsightPage()
- await expect(page).toHaveURL(/\/dashboard\//)
- await expect(page.locator('.InsightCard canvas').first()).toBeVisible()
- })
- })
-})
diff --git a/playwright/e2e/product-analytics/insight-json-tab.spec.ts b/playwright/e2e/product-analytics/insight-json-tab.spec.ts
new file mode 100644
index 000000000000..e1bc118f8115
--- /dev/null
+++ b/playwright/e2e/product-analytics/insight-json-tab.spec.ts
@@ -0,0 +1,32 @@
+import { Navigation } from '../../utils/navigation'
+import { PlaywrightWorkspaceSetupResult, expect, test } from '../../utils/workspace-test-base'
+
+let workspace: PlaywrightWorkspaceSetupResult | null = null
+
+test.beforeAll(async ({ playwrightSetup }) => {
+ workspace = await playwrightSetup.createWorkspace({ use_current_time: true, skip_onboarding: true })
+})
+
+test.beforeEach(async ({ page, playwrightSetup }) => {
+ await playwrightSetup.login(page, workspace!)
+})
+
+test('can open event explorer as an insight', async ({ page }) => {
+ const navigation = new Navigation(page)
+ await navigation.openHome()
+
+ await navigation.openMenuItem('activity')
+ await page.getByTestId('data-table-export-menu').click()
+ await page.getByTestId('open-json-editor-button').click()
+
+ await expect(page.getByTestId('insight-json-tab')).toHaveCount(1)
+})
+
+test('does not show the json tab usually', async ({ page }) => {
+ const navigation = new Navigation(page)
+ await navigation.openHome()
+
+ await navigation.openMenuItem('product-analytics')
+
+ await expect(page.getByTestId('insight-json-tab')).toHaveCount(0)
+})
diff --git a/playwright/e2e/product-analytics/insight-navigation.spec.ts b/playwright/e2e/product-analytics/insight-navigation.spec.ts
deleted file mode 100644
index 592ec8a9a116..000000000000
--- a/playwright/e2e/product-analytics/insight-navigation.spec.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import { InsightType } from '~/types'
-
-import { InsightPage } from '../../page-models/insightPage'
-import { Navigation } from '../../utils/navigation'
-import { PlaywrightWorkspaceSetupResult, expect, test } from '../../utils/workspace-test-base'
-
-let workspace: PlaywrightWorkspaceSetupResult | null = null
-
-test.beforeAll(async ({ playwrightSetup }) => {
- workspace = await playwrightSetup.createWorkspace({ use_current_time: true, skip_onboarding: true })
-})
-
-test.beforeEach(async ({ page, playwrightSetup }) => {
- await playwrightSetup.login(page, workspace!)
-})
-
-// `InsightType` values are uppercase enum keys (TRENDS, FUNNELS, …) but the
-// InsightsNav tab labels are sentence-cased ("Trends", "User Paths", …). The
-// `expectedTabText` lets each case opt out of the case-insensitive enum match
-// (e.g. PATHS → "User Paths") without bringing back per-type chart selectors —
-// the old `.TrendsInsight` / `.funnels-empty-state__title` ones are dead.
-const typeTestCases: { type: InsightType; expectedTabText: string }[] = [
- { type: InsightType.TRENDS, expectedTabText: 'Trends' },
- { type: InsightType.FUNNELS, expectedTabText: 'Funnels' },
- { type: InsightType.RETENTION, expectedTabText: 'Retention' },
- { type: InsightType.PATHS, expectedTabText: 'User Paths' },
- { type: InsightType.STICKINESS, expectedTabText: 'Stickiness' },
- { type: InsightType.LIFECYCLE, expectedTabText: 'Lifecycle' },
-]
-
-typeTestCases.forEach(({ type, expectedTabText }) => {
- test(`can navigate to ${type} insight from saved insights page`, async ({ page }) => {
- await new InsightPage(page).goToNew(type)
- await expect(page.locator('.LemonTabs__tab--active')).toContainText(expectedTabText)
-
- // Once data resolves the viz swaps in either the empty state
- // (`insight-empty-state`, tagged on every variant in EmptyStates.tsx), a
- // `<canvas>` (Trends/Funnels/Retention/Stickiness/Lifecycle), or the Paths
- // SVG container (`paths-viz`, which never renders a `<canvas>`). Treating any
- // as success keeps the smoke test stable across query backends and chart types.
- const emptyState = page.locator('[data-attr="insight-empty-state"]')
- const chartCanvas = page.locator('main canvas')
- const pathsViz = page.locator('[data-attr="paths-viz"]')
- await expect(emptyState.or(chartCanvas).or(pathsViz).first()).toBeVisible()
- })
-})
-
-test('can open event explorer as an insight', async ({ page }) => {
- const navigation = new Navigation(page)
- await navigation.openHome()
-
- await navigation.openMenuItem('activity')
- await page.getByTestId('data-table-export-menu').click()
- await page.getByTestId('open-json-editor-button').click()
-
- await expect(page.getByTestId('insight-json-tab')).toHaveCount(1)
-})
-
-test('does not show the json tab usually', async ({ page }) => {
- const navigation = new Navigation(page)
- await navigation.openHome()
-
- await navigation.openMenuItem('product-analytics')
-
- await expect(page.getByTestId('insight-json-tab')).toHaveCount(0)
-})
diff --git a/playwright/e2e/product-analytics/insights/lifecycle.spec.ts b/playwright/e2e/product-analytics/insights/lifecycle.spec.ts
new file mode 100644
index 000000000000..640fc1b9ef30
--- /dev/null
+++ b/playwright/e2e/product-analytics/insights/lifecycle.spec.ts
@@ -0,0 +1,35 @@
+import { InsightType } from '~/types'
+
+import { InsightPage } from '../../../page-models/insightPage'
+import { PlaywrightWorkspaceSetupResult, expect, test } from '../../../utils/workspace-test-base'
+
+test.describe('Lifecycle insights', () => {
+ let workspace: PlaywrightWorkspaceSetupResult | null = null
+
+ test.beforeAll(async ({ playwrightSetup }) => {
+ workspace = await playwrightSetup.createWorkspace({ use_current_time: true, skip_onboarding: true })
+ })
+
+ test.beforeEach(async ({ page, playwrightSetup }) => {
+ await playwrightSetup.login(page, workspace!)
+ })
+
+ test('verify chart and lifecycle toggles, save and persist', async ({ page }) => {
+ const insight = new InsightPage(page)
+
+ await test.step('navigate to new Lifecycle insight and wait for result', async () => {
+ await insight.goToNewInsight(InsightType.LIFECYCLE)
+ await expect(insight.activeTab).toContainText('Lifecycle')
+ await insight.lifecycle.waitForChart()
+ })
+
+ await test.step('verify lifecycle toggles section is present', async () => {
+ await expect(page.getByText('Lifecycle Toggles')).toBeVisible()
+ })
+
+ await test.step('save and verify view mode', async () => {
+ await insight.save()
+ await expect(insight.editButton).toBeVisible()
+ })
+ })
+})