test(e2e): add mock sidebar logout coverage

This commit is contained in:
2026-06-29 18:16:40 +08:00
parent e951d56076
commit 9ad17379e8
2 changed files with 48 additions and 0 deletions
+4
View File
@@ -21,6 +21,10 @@ export async function mockCoreApis(page: Page): Promise<void> {
await route.fulfill({ json: apiEnvelope(emailLoginResponse) });
});
await page.route("**/api/auth/logout", async (route) => {
await route.fulfill({ json: apiEnvelope(null) });
});
await page.route("**/api/user/profile", async (route) => {
await route.fulfill({ json: apiEnvelope(e2eEmailUser) });
});
@@ -0,0 +1,44 @@
import { expect, test } from "@playwright/test";
import { mockCoreApis } from "../../fixtures/api-mocks";
test.beforeEach(async ({ context, page }) => {
await context.clearCookies();
await mockCoreApis(page);
});
test("user can log out from the sidebar after email login", async ({
page,
}) => {
await page.goto("/auth");
await page.getByRole("button", { name: /Other Sign In Options/i }).click();
await expect(
page.getByRole("dialog", { name: /Other sign-in options/i }),
).toBeVisible();
await page.getByRole("button", { name: "Email Sign In" }).click();
await expect(page.getByPlaceholder("Email")).toHaveValue(
"chanwillian0@gmail.com",
);
await expect(page.getByPlaceholder("Password")).toHaveValue("12345678");
await page.getByRole("button", { name: "Login" }).click();
await expect(page).toHaveURL(/\/chat$/);
await expect(page.getByRole("button", { name: "Menu" })).toBeVisible();
await page.getByRole("button", { name: "Menu" }).click();
await expect(page).toHaveURL(/\/sidebar$/);
const logoutRequestPromise = page.waitForRequest("**/api/auth/logout");
await page.getByRole("button", { name: /Log out/i }).click();
const logoutRequest = await logoutRequestPromise;
expect(logoutRequest.method()).toBe("POST");
await expect(page).toHaveURL(/\/splash$/);
await expect(page.getByRole("button", { name: "Skip" })).toBeVisible();
await expect(
page.getByRole("button", { name: "Login with Facebook" }),
).toBeVisible();
});