From ec383f6eef6fa8c467965b6be89acfd40f81b8cb Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Wed, 14 Jan 2026 15:14:05 -0300 Subject: [PATCH] fix: make flaky E2E tests more stable (#26844) * fix: make flaky E2E tests more stable - Add waitForFunction for localStorage check in change-theme test to wait for app-theme to be set before asserting - Use waitUntil: 'domcontentloaded' for waitForURL calls in routing-forms tests to handle client-side navigation more reliably Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Anik Dhabal Babu --- apps/web/components/apps/routing-forms/SingleForm.tsx | 2 ++ apps/web/playwright/change-theme.e2e.ts | 11 +++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/web/components/apps/routing-forms/SingleForm.tsx b/apps/web/components/apps/routing-forms/SingleForm.tsx index 51514e743e..2414a94aac 100644 --- a/apps/web/components/apps/routing-forms/SingleForm.tsx +++ b/apps/web/components/apps/routing-forms/SingleForm.tsx @@ -132,6 +132,8 @@ function SingleForm({ }, [form]); const mutation = trpc.viewer.appRoutingForms.formMutation.useMutation({ onSuccess() { + const currentValues = hookForm.getValues(); + hookForm.reset(currentValues); showToast(t("form_updated_successfully"), "success"); }, onError(e) { diff --git a/apps/web/playwright/change-theme.e2e.ts b/apps/web/playwright/change-theme.e2e.ts index adee17b390..174f62c6ef 100644 --- a/apps/web/playwright/change-theme.e2e.ts +++ b/apps/web/playwright/change-theme.e2e.ts @@ -17,8 +17,7 @@ test.describe("Change App Theme Test", () => { const darkModeClass = await page.getAttribute("html", "class"); expect(darkModeClass).toContain("dark"); - const themeValue = await page.evaluate(() => localStorage.getItem("app-theme")); - expect(themeValue).toBe("dark"); + await page.waitForFunction(() => localStorage.getItem("app-theme") === "dark"); }); test("change app theme to light", async ({ page, users }) => { @@ -35,8 +34,7 @@ test.describe("Change App Theme Test", () => { const darkModeClass = await page.getAttribute("html", "class"); expect(darkModeClass).toContain("light"); - const themeValue = await page.evaluate(() => localStorage.getItem("app-theme")); - expect(themeValue).toBe("light"); + await page.waitForFunction(() => localStorage.getItem("app-theme") === "light"); }); test("change app theme to system", async ({ page, users }) => { @@ -54,10 +52,7 @@ test.describe("Change App Theme Test", () => { await page.click('[data-testid="update-app-theme-btn"]'); const toast2 = await page.waitForSelector('[data-testid="toast-success"]'); expect(toast2).toBeTruthy(); - - await page.waitForTimeout(3000); - const themeValue = await page.evaluate(() => localStorage.getItem("app-theme")); - expect(themeValue).toBe("light"); + await page.waitForFunction(() => localStorage.getItem("app-theme") === "light"); const systemTheme = await page.evaluate(() => { return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";