mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-04 00:53:57 +00:00
chore: scaffold apps/basic from with-lingui
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { expect } from "@playwright/test";
|
||||
import type { Page } from "@playwright/test";
|
||||
|
||||
export async function loginAsAdmin(page: Page) {
|
||||
await page.goto("/login");
|
||||
await page.getByLabel(/Username|用户名/).fill("admin");
|
||||
await page.getByLabel(/Password|密码/).fill("admin");
|
||||
await page.getByRole("button", { name: /Sign In|登录/ }).click();
|
||||
await expect(page).toHaveURL(/dashboard/);
|
||||
}
|
||||
|
||||
export async function gotoUsers(page: Page) {
|
||||
await loginAsAdmin(page);
|
||||
await page.goto("/users");
|
||||
await expect(page).toHaveURL(/users/);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
import { loginAsAdmin } from "./helpers";
|
||||
|
||||
test.describe("Login Flow", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto("/login");
|
||||
});
|
||||
|
||||
test("should display login form", async ({ page }) => {
|
||||
await expect(page.getByLabel(/Username|用户名/)).toBeVisible();
|
||||
await expect(page.getByLabel(/Password|密码/)).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: /Sign In|登录/ })).toBeVisible();
|
||||
});
|
||||
|
||||
test("should login successfully with admin/admin", async ({ page }) => {
|
||||
await loginAsAdmin(page);
|
||||
await expect(page.getByText("Total Revenue")).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show error for wrong credentials", async ({ page }) => {
|
||||
await page.getByLabel(/Username|用户名/).fill("wrong");
|
||||
await page.getByLabel(/Password|密码/).fill("wrong");
|
||||
await page.getByRole("button", { name: /Sign In|登录/ }).click();
|
||||
|
||||
await expect(page.getByText("Invalid username or password")).toBeVisible();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
import { gotoUsers, loginAsAdmin } from "./helpers";
|
||||
|
||||
test.describe("User Management", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await gotoUsers(page);
|
||||
});
|
||||
|
||||
test("should display user table", async ({ page }) => {
|
||||
const thead = page.locator(".ant-table-thead");
|
||||
await expect(thead.getByText(/Username|用户名/)).toBeVisible();
|
||||
await expect(thead.getByText(/Email|邮箱/)).toBeVisible();
|
||||
await expect(thead.getByText(/Roles|角色/)).toBeVisible();
|
||||
});
|
||||
|
||||
test("should search users", async ({ page }) => {
|
||||
const searchInput = page.getByPlaceholder(/Search User|搜索用户/);
|
||||
await searchInput.fill("zhao.ming");
|
||||
await searchInput.press("Enter");
|
||||
await expect(page).toHaveURL(/keyword=zhao\.ming/);
|
||||
/* Avoid strict-mode match on email cell containing substring "zhao.ming" */
|
||||
await expect(page.getByText("zhao.ming", { exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test("should open create user modal", async ({ page }) => {
|
||||
await page.getByRole("button", { name: /Create User|创建用户/ }).click();
|
||||
await expect(page.getByRole("dialog").getByText(/New User|新建用户/)).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
/** Avoid a second full `page.goto` after `/users`: reload can land on login before auth rehydrates. */
|
||||
test.describe("User Management — role in URL", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await loginAsAdmin(page);
|
||||
await page.goto("/users?role=admin");
|
||||
await expect(page.getByPlaceholder(/Search User|搜索用户/)).toBeVisible({ timeout: 15_000 });
|
||||
});
|
||||
|
||||
test("should filter users by role", async ({ page }) => {
|
||||
await expect(page).toHaveURL(/role=admin/);
|
||||
await expect(page.getByRole("cell", { name: "ops.admin@northstar.io" })).toBeVisible();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user