From 2b8a2c9c5dcc9796684ee35b429089d6e4c5a6e9 Mon Sep 17 00:00:00 2001 From: Jake Howell Date: Tue, 21 Apr 2026 23:34:10 +1000 Subject: [PATCH] fix(site/e2e): wait for file upload before submitting create template form (#24548) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > 🤖 This PR was written by Coder Agent on behalf of Jake Howell Fixes https://github.com/coder/internal/issues/1419 The `createTemplate` e2e helper clicks Save immediately after `setInputFiles`, but the file upload API call is fire-and-forget through the React component chain (`FileUpload.onChange` → `CreateTemplateForm.onUpload` → `UploadTemplateView.onUpload` — none of which `await` the returned promise up the chain). If the upload mutation has not settled when the form submits, `uploadedFile` (`uploadFileMutation.data`) is still `undefined`, and the `uploadedFile!.hash` non-null assertion throws a `TypeError`. Formik silently swallows the rejected promise, so the page stays on `/templates/new` and the URL assertion times out. The fix waits for the "Remove file" button to appear after `setInputFiles`. That button only renders when `!isPending && variables` — i.e. the upload mutation has succeeded and the hash is available. --- site/e2e/helpers.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/site/e2e/helpers.ts b/site/e2e/helpers.ts index 8dee74a1ef..d680a3cf8b 100644 --- a/site/e2e/helpers.ts +++ b/site/e2e/helpers.ts @@ -294,6 +294,13 @@ export const createTemplate = async ( mimeType: "application/x-tar", name: "template.tar", }); + // setInputFiles triggers the upload API call through React's + // onChange handler, but the call is fire-and-forget (not awaited + // in the component chain). Wait for the upload to finish so + // uploadedFile.hash is available when the form submits. + await expect( + page.getByRole("button", { name: "Remove file" }), + ).toBeVisible(); } // If the organization picker is present on the page, select the default