From 53ef63145bab905b4996e17048752fcf179b8dea Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Fri, 16 Oct 2026 15:46:10 -0700 Subject: [PATCH] test(ui): wait for the logout navigation before checking the session is gone (#47008) --- tests/e2e/ui/tests/auth/logout.spec.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/e2e/ui/tests/auth/logout.spec.ts b/tests/e2e/ui/tests/auth/logout.spec.ts index fcdd71898e2..8d251d52ef7 100644 --- a/tests/e2e/ui/tests/auth/logout.spec.ts +++ b/tests/e2e/ui/tests/auth/logout.spec.ts @@ -2,6 +2,8 @@ import { test, expect } from "@playwright/test"; import { Role, users } from "../../fixtures/users"; import { logInThroughLoginPage } from "../../helpers/userOnboarding"; +const LOGOUT_URL = process.env.PROXY_LOGOUT_URL ?? ""; + test.describe("Logout", () => { test.use({ storageState: { cookies: [], origins: [] } }); @@ -9,9 +11,21 @@ test.describe("Logout", () => { const admin = users[Role.ProxyAdmin]; await logInThroughLoginPage(page, admin.email, admin.password); + if (LOGOUT_URL) { + const target = new URL(LOGOUT_URL); + await page.route( + (url) => url.origin === target.origin, + (route) => + route.fulfill({ status: 200, contentType: "text/html", body: "logged out" }), + ); + } + const settingsLoaded = page.waitForResponse((r) => r.url().includes("/sso/get/ui_settings") && r.ok(), { + timeout: 30_000, + }); await page.goto("/ui"); // Scope to the sidebar; the top-bar breadcrumb also shows "Virtual Keys". await expect(page.getByRole("complementary").getByText("Virtual Keys")).toBeVisible({ timeout: 10_000 }); + await settingsLoaded; // Open the sidebar account menu. The trigger button exposes an aria-label // of "Account menu — — signed in as "; clicking it opens the @@ -22,8 +36,12 @@ test.describe("Logout", () => { await expect(popup).toBeVisible({ timeout: 5_000 }); // Click Logout — the handler clears the auth cookie and navigates via - // window.location.href = PROXY_LOGOUT_URL (empty string in the e2e env). + // window.location.href = PROXY_LOGOUT_URL. + const loggedOut = LOGOUT_URL + ? page.waitForURL((url) => url.origin === new URL(LOGOUT_URL).origin, { timeout: 15_000 }) + : page.waitForEvent("load", { timeout: 15_000 }); await popup.getByRole("button", { name: "Logout" }).click(); + await loggedOut; await expect .poll(async () => (await page.context().cookies()).filter((c) => c.name === "token").length, { timeout: 15_000,