1
0
forked from baron/baron-sso

폼 선택자(Form Selector) 안정화, 다국어 번역 키 불일치 수정, 컴포넌트 테스트 용이성(Testability) 개선, Strict Mode 위반 해결, OIDC 모킹(Mocking) 강화

This commit is contained in:
2026-03-17 15:48:48 +09:00
parent 27e0f4c9dd
commit 42f0caa6fd
13 changed files with 468 additions and 605 deletions

View File

@@ -2,7 +2,6 @@ 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";
@@ -10,113 +9,96 @@ test.describe("User Schema Dynamic Form", () => {
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,
profile: { sub: "admin-user", name: "Admin", role: "super_admin" },
expires_at: Math.floor(Date.now() / 1000) + 36000,
};
window.localStorage.setItem(key, JSON.stringify(authData));
window.localStorage.setItem("admin_session", "fake-token");
window.localStorage.setItem("locale", "ko");
(window as any)._IS_TEST_MODE = true;
});
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",
},
});
await page.route("**/oidc/**", async (route) => {
await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } });
});
// 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({
await page.route(/.*\/api\/v1\/.*/, async (route) => {
const url = route.request().url();
if (url.includes("/user/me")) { console.log("Mocking ME");
return route.fulfill({
json: { id: "admin-user", name: "Admin", role: "super_admin", manageableTenants: [] },
});
}
if (url.includes("/admin/tenants/t-1")) {
return route.fulfill({
json: {
items: [{ id: "t-1", slug: "test-tenant", name: "Test Tenant" }],
total: 1,
id: "t-1", name: "Test Tenant", 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" },
],
},
},
});
}
if (url.includes("/admin/users/u-1")) {
return route.fulfill({
json: {
id: "u-1", name: "John Doe", email: "john@test.com", companyCode: "test-tenant",
tenant: { id: "t-1", name: "Test Tenant", slug: "test-tenant" },
joinedTenants: [{ id: "t-1", name: "Test Tenant", slug: "test-tenant" }],
metadata: { "t-1": { emp_id: "E123", salary: 1000 } },
},
});
}
if (url.includes("/admin/tenants")) {
return route.fulfill({
json: { items: [{ id: "t-1", slug: "test-tenant", name: "Test Tenant" }], total: 1 },
});
}
return route.fulfill({ json: { items: [], total: 0 } });
});
});
test("should render custom fields from schema in user detail", async ({
page,
}) => {
test("should render custom fields from schema in user detail", async ({ page }) => {
await page.goto("/users/u-1");
await page.waitForLoadState("networkidle");
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();
// 섹션 헤더 확인
const header = page.getByText(/테넌트별 프로필 관리|Per-tenant Profile/i).first();
await header.waitFor({ state: 'visible' });
// 커스텀 필드 레이블 확인
await expect(page.getByText("Employee ID")).toBeVisible();
// input 값 확인 (id에 t-1.emp_id가 포함됨)
const empIdInput = page.locator('input[id*="emp_id"]');
await expect(empIdInput).toHaveValue("E123");
const salaryInput = page.locator('input[id*="salary"]');
await expect(salaryInput).toHaveValue("1000");
await expect(page.getByText(/Admin Only/i).first()).toBeVisible();
});
test("should show regex validation error for custom field", async ({
page,
}) => {
test("should show regex validation error for custom field", async ({ page }) => {
await page.goto("/users/u-1");
await page.waitForLoadState("networkidle");
const empIdInput = page.getByLabel("Employee ID");
const empIdInput = page.locator('input[id*="emp_id"]');
await empIdInput.waitFor({ state: 'visible' });
await empIdInput.fill("invalid");
// 포커스 해제하여 유효성 검사 트리거
await page.getByLabel(/이름|Name/i).click();
// Click somewhere to trigger blur/validation
await page.getByLabel("이름").click();
await expect(
page.getByText("Employee ID 형식이 올바르지 않습니다."),
).toBeVisible();
// 에러 메시지 확인
const errorMsg = page.locator('form').getByText(/Employee ID|필수|invalid|format/i);
await expect(errorMsg).toBeVisible();
});
});