From dea451de417c2213729931193c17ae7a98fad69e Mon Sep 17 00:00:00 2001 From: Jeremy Ruppel Date: Fri, 27 Feb 2026 08:59:22 -0500 Subject: [PATCH] fix(site): await dialog close after publish to prevent act() warnings (#22334) State updates from setIsPublishingDialogOpen, setLastSuccessfulPublishedVersion, and navigation were firing after waitFor resolved, causing sporadic act() warnings and timeouts in the publish template version tests (or so says Claude Sonnet 4.6). 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 a3c71bce0f..1bed974d2e 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 () => {