From fc908063d93fac546c426d27bb2a6f58bfb8c87a Mon Sep 17 00:00:00 2001 From: Sandy Spicer Date: Thu, 13 Jun 2024 16:00:17 -0700 Subject: [PATCH] chore: insight flapping (#22966) Fix flapping with belt and suspenders --- .storybook/test-runner.ts | 19 ++++++++++++------- .../insights/__mocks__/createInsightScene.tsx | 1 - 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.storybook/test-runner.ts b/.storybook/test-runner.ts index 76588ffb1f275..24cb830f76ddd 100644 --- a/.storybook/test-runner.ts +++ b/.storybook/test-runner.ts @@ -155,18 +155,17 @@ async function expectStoryToMatchSnapshot( await Promise.all(waitForSelector.map((selector) => page.waitForSelector(selector))) } - await page.waitForTimeout(400) // Wait for effects to finish - - // Wait for all images to load - await page.waitForFunction(() => - Array.from(document.querySelectorAll('img')).every((i: HTMLImageElement) => i.complete) - ) - // snapshot light theme await page.evaluate(() => { document.body.setAttribute('theme', 'light') }) + // Wait for all images to load + await page.waitForFunction(() => Array.from(document.images).every((i: HTMLImageElement) => i.complete)) + await waitForPageReady(page) + await page.waitForLoadState('networkidle') + await page.waitForTimeout(2000) + await check(page, context, browser, 'light', storyContext.parameters?.testOptions?.snapshotTargetSelector) // snapshot dark theme @@ -174,6 +173,12 @@ async function expectStoryToMatchSnapshot( document.body.setAttribute('theme', 'dark') }) + // Wait for all images to load + await page.waitForFunction(() => Array.from(document.images).every((i: HTMLImageElement) => i.complete)) + await waitForPageReady(page) + await page.waitForLoadState('networkidle') + await page.waitForTimeout(100) + await check(page, context, browser, 'dark', storyContext.parameters?.testOptions?.snapshotTargetSelector) } diff --git a/frontend/src/scenes/insights/__mocks__/createInsightScene.tsx b/frontend/src/scenes/insights/__mocks__/createInsightScene.tsx index 80911e832da8e..3bbfcce25dbe5 100644 --- a/frontend/src/scenes/insights/__mocks__/createInsightScene.tsx +++ b/frontend/src/scenes/insights/__mocks__/createInsightScene.tsx @@ -17,7 +17,6 @@ export function createInsightStory( useStorybookMocks({ get: { '/api/projects/:team_id/insights/': (_, __, ctx) => [ - ctx.delay(100), ctx.status(200), ctx.json({ count: 1,