import { test, expect } from "./fixtures"; import { freshAccount, loginViaUi } from "./helpers"; test.describe("authentication", () => { test("unauthenticated user is redirected to the login page", async ({ page, }) => { await page.goto("/conversations"); await expect(page).toHaveURL(/\/login\?redirect=/); await expect( page.getByRole("button", { name: /获取演示验证码/ }), ).toBeVisible(); }); test("demo login reaches the sea home and persists across reload", async ({ page, }) => { const account = freshAccount("137"); await loginViaUi(page, account); await expect(page.getByRole("link", { name: /扔一只瓶子/ })).toBeVisible(); await page.reload(); await expect(page).toHaveURL(/\/$/); await expect(page.getByRole("link", { name: /扔一只瓶子/ })).toBeVisible(); }); test("logout returns to login and clears the session", async ({ page }) => { const account = freshAccount("136"); await loginViaUi(page, account); await page.goto("/settings"); await page.getByRole("button", { name: "退出登录" }).click(); await expect(page).toHaveURL(/\/login/); await page.goto("/"); await expect(page).toHaveURL(/\/login\?redirect=/); }); });