From 148c6ae634f2b682d910cc33dfcb2edf437f59c4 Mon Sep 17 00:00:00 2001 From: Jeremy Ruppel Date: Thu, 26 Feb 2026 11:41:55 -0500 Subject: [PATCH] fix(site): await dialog close after publish to prevent act() warnings State updates from setIsPublishingDialogOpen, setLastSuccessfulPublishedVersion, and navigation were firing after waitFor resolved, causing sporadic act() warnings and timeouts in the publish template version tests. Fixes coder/internal#1369 Co-Authored-By: Claude Sonnet 4.6 --- .../TemplateVersionEditorPage.test.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx b/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx index a3c71bce0f0c7..1bed974d2ea76 100644 --- a/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx +++ b/site/src/pages/TemplateVersionEditorPage/TemplateVersionEditorPage.test.tsx @@ -147,9 +147,14 @@ test("Use custom name, message and set it as active when publishing", async () = name: "v1.0", message: "Informative message", }); + expect(updateActiveTemplateVersion).toBeCalledWith("test-template", { + id: "new-version-id", + }); }); - expect(updateActiveTemplateVersion).toBeCalledWith("test-template", { - id: "new-version-id", + // Wait for the dialog to close so all async state updates (setIsPublishingDialogOpen, + // setLastSuccessfulPublishedVersion, navigation) settle before the test ends. + await waitFor(() => { + expect(screen.queryByTestId("dialog")).not.toBeInTheDocument(); }); }); @@ -195,6 +200,11 @@ test("Do not mark as active if promote is not checked", async () => { }); }); expect(updateActiveTemplateVersion).toBeCalledTimes(0); + // Wait for the dialog to close so all async state updates settle before the + // test ends, preventing act() warnings from pending state mutations. + await waitFor(() => { + expect(screen.queryByTestId("dialog")).not.toBeInTheDocument(); + }); }); test("Patch request is not send when there are no changes", async () => {