forked from baron/baron-sso
88 lines
2.9 KiB
TypeScript
88 lines
2.9 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
test.describe("User Schema Dynamic Form", () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
// Authenticate
|
|
await page.addInitScript(() => {
|
|
const authority = "http://localhost:5000/oidc";
|
|
const client_id = "adminfront";
|
|
const key = `oidc.user:${authority}:${client_id}`;
|
|
const authData = {
|
|
access_token: "fake-token",
|
|
token_type: "Bearer",
|
|
profile: { sub: "admin-user", name: "Admin User", email: "admin@example.com" },
|
|
expires_at: Math.floor(Date.now() / 1000) + 3600,
|
|
};
|
|
window.localStorage.setItem(key, JSON.stringify(authData));
|
|
});
|
|
|
|
await page.route("**/oidc/.well-known/openid-configuration", async (route) => {
|
|
await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } });
|
|
});
|
|
|
|
await page.route("**/api/v1/user/me", async (route) => {
|
|
await route.fulfill({
|
|
json: { id: "admin-user", name: "Admin User", email: "admin@example.com", role: "super_admin" },
|
|
});
|
|
});
|
|
|
|
// Mock Tenant with User Schema
|
|
await page.route("**/api/v1/admin/tenants/t-1", async (route) => {
|
|
await route.fulfill({
|
|
json: {
|
|
id: "t-1",
|
|
slug: "test-tenant",
|
|
config: {
|
|
userSchema: [
|
|
{ key: "emp_id", label: "Employee ID", required: true, validation: "^E[0-9]{3}$" },
|
|
{ key: "salary", label: "Salary", adminOnly: true, type: "number" }
|
|
]
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// Mock User
|
|
await page.route("**/api/v1/admin/users/u-1", async (route) => {
|
|
await route.fulfill({
|
|
json: {
|
|
id: "u-1",
|
|
name: "John Doe",
|
|
email: "john@test.com",
|
|
companyCode: "test-tenant",
|
|
metadata: { emp_id: "E123", salary: 1000 }
|
|
}
|
|
});
|
|
});
|
|
|
|
await page.route("**/api/v1/admin/tenants**", async (route) => {
|
|
if (route.request().method() === "GET") {
|
|
await route.fulfill({ json: { items: [{id: "t-1", slug: "test-tenant", name: "Test Tenant"}], total: 1 } });
|
|
}
|
|
});
|
|
});
|
|
|
|
test("should render custom fields from schema in user detail", async ({ page }) => {
|
|
await page.goto("/users/u-1");
|
|
|
|
await expect(page.getByText("테넌트 확장 정보 (Custom Fields)")).toBeVisible();
|
|
await expect(page.getByLabel("Employee ID")).toHaveValue("E123");
|
|
await expect(page.getByLabel("Salary")).toHaveValue("1000");
|
|
|
|
// Check for Admin Only badge
|
|
await expect(page.getByText("Admin Only")).toBeVisible();
|
|
});
|
|
|
|
test("should show regex validation error for custom field", async ({ page }) => {
|
|
await page.goto("/users/u-1");
|
|
|
|
const empIdInput = page.getByLabel("Employee ID");
|
|
await empIdInput.fill("invalid");
|
|
|
|
// Click somewhere to trigger blur/validation
|
|
await page.getByLabel("이름").click();
|
|
|
|
await expect(page.getByText("Employee ID 형식이 올바르지 않습니다.")).toBeVisible();
|
|
});
|
|
});
|