Files

45 lines
1.8 KiB
TypeScript

import { test, expect } from "@playwright/test";
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
const brand = {
id: "session-brand-fixture",
name: "会话恢复品牌",
slug: "session-brand",
templateKey: "food",
};
test("首次登录修改密码后直接恢复后台", async ({ page }) => {
let passwordChanged = false;
await page.setViewportSize({ width: 1440, height: 900 });
await page.route("**/api/**", async (route) => {
const path = new URL(route.request().url()).pathname.replace(/^\/api/, "");
if (path === "/admin/session/current") {
return route.fulfill({
json: {
authenticated: true,
displayName: "首次登录管理员",
role: "editor",
mustChangePassword: !passwordChanged,
platformTemplateRole: "none",
},
});
}
if (path === "/admin/session/change-password" && route.request().method() === "POST") {
passwordChanged = true;
return route.fulfill({ json: { changed: true } });
}
if (path === "/admin/config/brand") return route.fulfill({ json: brand });
if (path === "/admin/brands") return route.fulfill({ json: [] });
return route.fulfill({ json: {} });
});
await page.goto(`${adminOrigin}/admin/brand`);
await expect(page.getByText("首次登录需要修改密码")).toBeVisible();
await page.getByLabel("初始密码").fill("initial-password-123");
await page.getByLabel("新密码", { exact: true }).fill("updated-password-123");
await page.getByLabel("确认密码").fill("updated-password-123");
await page.getByRole("button", { name: "保存新密码" }).click();
await expect(page.locator(".admin-shell")).toBeVisible();
await expect(page.getByText("首次登录需要修改密码")).toBeHidden();
});