91 lines
3.4 KiB
TypeScript
91 lines
3.4 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
import { mockBackend } from "./support/mockBackend";
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
await mockBackend(page);
|
|
});
|
|
|
|
test("已登录管理员可以打开审计日志页面", async ({ page }) => {
|
|
await page.goto("/audit-logs");
|
|
|
|
await expect(
|
|
page.getByRole("heading", { name: "审计日志", exact: true }),
|
|
).toBeVisible();
|
|
await expect(page.getByText("系统管理员权限已验证")).toBeVisible();
|
|
await expect(page.getByRole("heading", { name: "查询结果" })).toBeVisible();
|
|
});
|
|
|
|
test("已认证但未授权的账号会看到明确说明", async ({ page }) => {
|
|
await page.addInitScript(() => window.localStorage.clear());
|
|
await page.route("**/api/v1/access-context", (route) =>
|
|
route.fulfill({
|
|
status: 403,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({ detail: "User authorization pending" }),
|
|
}),
|
|
);
|
|
|
|
await page.goto("/");
|
|
|
|
await expect(page.getByText("账号尚未获得访问权限")).toBeVisible();
|
|
await expect(
|
|
page.getByText("身份认证已成功,但当前账号尚未由系统管理员启用"),
|
|
).toBeVisible();
|
|
const accountMenu = page.getByRole("button", {
|
|
name: "E2E 测试用户 账号菜单",
|
|
});
|
|
await expect(accountMenu).toBeVisible();
|
|
await accountMenu.click();
|
|
await expect(page.getByRole("menuitem", { name: "登出" })).toBeVisible();
|
|
await expect(page.getByRole("menuitem", { name: "切换项目" })).toHaveCount(0);
|
|
await page.keyboard.press("Escape");
|
|
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await expect(page.getByText("账号尚未获得访问权限")).toBeVisible();
|
|
await expect(accountMenu).toBeVisible();
|
|
});
|
|
|
|
test("无权访问项目时可以在窄屏切换项目", async ({ page }) => {
|
|
await page.route("**/api/v1/access-context", (route) =>
|
|
route.fulfill({
|
|
status: 403,
|
|
contentType: "application/json",
|
|
body: JSON.stringify({ detail: "No access to project" }),
|
|
}),
|
|
);
|
|
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await page.goto("/");
|
|
|
|
await expect(page.getByText("无权访问当前项目")).toBeVisible();
|
|
await page
|
|
.getByRole("button", { name: "E2E 测试用户 账号菜单" })
|
|
.click();
|
|
await page.getByRole("menuitem", { name: "切换项目" }).click();
|
|
|
|
const projectDialog = page.getByRole("dialog");
|
|
await expect(projectDialog).toBeVisible();
|
|
const bounds = await projectDialog.boundingBox();
|
|
expect(bounds).not.toBeNull();
|
|
expect(bounds!.x).toBeGreaterThanOrEqual(0);
|
|
expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(390);
|
|
});
|
|
|
|
test("系统管理员可以手动同步 Keycloak 用户目录", async ({ page }) => {
|
|
await page.goto("/system-admin");
|
|
await page.getByRole("tab", { name: "系统用户" }).click();
|
|
|
|
await page.getByRole("button", { name: "同步 Keycloak 用户" }).click();
|
|
await expect(page.getByRole("button", { name: "正在同步" })).toBeDisabled();
|
|
|
|
await expect(
|
|
page.getByText("已扫描 3 个 Keycloak 身份,新增 1 个,更新 1 个,跳过 1 个。"),
|
|
).toBeVisible();
|
|
await expect(page.getByText("跳过项包括服务账号、缺少邮箱或身份冲突")).toBeVisible();
|
|
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await expect(page.getByRole("button", { name: "同步 Keycloak 用户" })).toBeVisible();
|
|
await expect(page.getByRole("button", { name: "刷新", exact: true })).toBeVisible();
|
|
});
|