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(playwright): drain discard-triggered insight re-fetch to deflake trends save test (#63109)

Sam Penningtonf95f07f48d99
diff --git a/playwright/e2e/product-analytics/insights/funnels.spec.ts b/playwright/e2e/product-analytics/insights/funnels.spec.ts
index 3cbfec2b7e10..df9906b0de29 100644
--- a/playwright/e2e/product-analytics/insights/funnels.spec.ts
+++ b/playwright/e2e/product-analytics/insights/funnels.spec.ts
@@ -409,8 +409,7 @@ test.describe('Funnel insights', () => {
})
await test.step('cancel edit — conversion window reverts to saved value', async () => {
- await insight.cancelButton.click()
- await expect(insight.editButton).toBeVisible()
+ await insight.discard()
await insight.funnels.waitForChart()
await insight.edit()
@@ -453,8 +452,7 @@ test.describe('Funnel insights', () => {
})
await test.step('cancel restores original state after discard flow', async () => {
- await insight.cancelButton.click()
- await expect(insight.editButton).toBeVisible()
+ await insight.discard()
await insight.edit()
await expect(insight.funnels.conversionWindowInput).not.toHaveValue('3')
diff --git a/playwright/e2e/product-analytics/insights/trends.spec.ts b/playwright/e2e/product-analytics/insights/trends.spec.ts
index 8baf0803b270..8a938fa24032 100644
--- a/playwright/e2e/product-analytics/insights/trends.spec.ts
+++ b/playwright/e2e/product-analytics/insights/trends.spec.ts
@@ -21,6 +21,19 @@ test.describe('Trends insights', () => {
await playwrightSetup.login(page, workspace!)
})
+ // Changing the date range right after entering edit mode can race the editor's
+ // hydration — a late insight load can revert the edit, leaving the save button stuck
+ // on "No changes". Require the dirty state to stick and re-apply if it was reverted.
+ async function selectDateRangeUntilDirty(insight: InsightPage, label: string): Promise<void> {
+ await expect(async () => {
+ await insight.trends.selectDateRange(label)
+ await expect(insight.saveButton).not.toContainText('No changes', { timeout: 2000 })
+ await insight.page.waitForTimeout(300)
+ await expect(insight.saveButton).not.toContainText('No changes', { timeout: 500 })
+ await expect(insight.saveButton).toBeEnabled({ timeout: 500 })
+ }).toPass({ timeout: 30000 })
+ }
+
test('View default pageview trends and verify daily totals', async ({ page }) => {
const insight = new InsightPage(page)
@@ -320,7 +333,7 @@ test.describe('Trends insights', () => {
})
await test.step('change date range then discard and verify revert', async () => {
- await insight.trends.selectDateRange('Last 30 days')
+ await selectDateRangeUntilDirty(insight, 'Last 30 days')
await expect(insight.trends.dateRangeButton).toContainText('Last 30 days')
await expect(insight.saveButton).toBeEnabled()
await insight.discard()
@@ -333,7 +346,7 @@ test.describe('Trends insights', () => {
await test.step('edit again, make a change, and save', async () => {
await insight.edit()
- await insight.trends.selectDateRange('Last 14 days')
+ await selectDateRangeUntilDirty(insight, 'Last 14 days')
await insight.save()
await expect(insight.trends.dateRangeButton).toContainText('Last 14 days')
})
diff --git a/playwright/page-models/insightPage.ts b/playwright/page-models/insightPage.ts
index 415c8b4a4cf1..bd1f36751e78 100644
--- a/playwright/page-models/insightPage.ts
+++ b/playwright/page-models/insightPage.ts
@@ -178,8 +178,13 @@ export class InsightPage {
}
async discard(): Promise<void> {
+ // Discarding switches back to view mode, which re-fetches the insight. Drain that
+ // fetch before returning — left in flight, its response can land after a later
+ // edit and clobber it (see waitForInsightLoad).
+ const insightReloaded = this.waitForInsightLoad()
await this.page.getByTestId('insight-cancel-edit-button').click()
await expect(this.editButton).toBeVisible()
+ await insightReloaded
}
async editName(insightName: string = randomString('insight')): Promise<void> {