test(ui): wait for the logout navigation before checking the session is gone (#47008)

This commit is contained in:
yuneng-jiang 2026-10-16 15:46:10 -07:00 • committed by GitHub
parent e9a8581a02
commit 53ef63145b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: "<html><body>logged out</body></html>" }),
);
}
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 — <role> — signed in as <email>"; 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,