1
0
forked from baron/baron-sso

Playwright 테스트 오류 수정

This commit is contained in:
2026-03-18 09:05:50 +09:00
parent ec8abf39aa
commit d305398326
13 changed files with 387 additions and 149 deletions

View File

@@ -46,13 +46,16 @@ function AppLayout() {
enabled:
(auth.isAuthenticated && !auth.isLoading) ||
import.meta.env.MODE === "development" ||
(window as any)._IS_TEST_MODE === true,
(window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean })
._IS_TEST_MODE === true,
});
const navItems = React.useMemo(() => {
const items = [...staticNavItems];
const isTest = (window as any)._IS_TEST_MODE === true;
const isTest =
(window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean })
._IS_TEST_MODE === true;
// 테스트 모드이면 profile이 없어도 super_admin으로 간주하여 모든 메뉴 렌더링
const isSuperAdmin = isTest || profile?.role === "super_admin";
const isTenantAdmin = profile?.role === "tenant_admin";

View File

@@ -109,7 +109,10 @@ function TenantCreatePage() {
name="name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder={t("ui.admin.tenants.create.form.name_placeholder", "테넌트 이름을 입력하세요")}
placeholder={t(
"ui.admin.tenants.create.form.name_placeholder",
"테넌트 이름을 입력하세요",
)}
/>
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
@@ -183,7 +186,10 @@ function TenantCreatePage() {
/>
</div>
<div className="space-y-2">
<Label htmlFor="tenant-description" className="text-sm font-semibold">
<Label
htmlFor="tenant-description"
className="text-sm font-semibold"
>
{t("ui.admin.tenants.create.form.description", "설명")}
</Label>
<Textarea

View File

@@ -111,7 +111,11 @@ ${example}`,
}}
>
<DialogTrigger asChild>
<Button variant="outline" className="gap-2" data-testid="bulk-import-btn">
<Button
variant="outline"
className="gap-2"
data-testid="bulk-import-btn"
>
<Upload size={16} />
{t("ui.admin.users.list.bulk_import", "일괄 등록 (CSV)")}
</Button>

View File

@@ -1,7 +1,10 @@
import axios from "axios";
const apiClient = axios.create({
baseURL: (window as any)._IS_TEST_MODE ? "http://playwright-mock/api" : (import.meta.env.VITE_ADMIN_API_BASE ?? "/api"),
baseURL: (window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean })
._IS_TEST_MODE
? "http://playwright-mock/api"
: (import.meta.env.VITE_ADMIN_API_BASE ?? "/api"),
});
apiClient.interceptors.request.use((config) => {

View File

@@ -6,15 +6,22 @@ test.describe("Authentication", () => {
await page.addInitScript(() => {
window.localStorage.setItem("locale", "ko");
window.localStorage.setItem("admin_session", "fake-token");
(window as any)._IS_TEST_MODE = true;
(
window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean }
)._IS_TEST_MODE = true;
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", email: "admin@test.com", role: "super_admin" },
profile: {
sub: "admin-user",
name: "Admin",
email: "admin@test.com",
role: "super_admin",
},
expires_at: Math.floor(Date.now() / 1000) + 36000,
};
window.localStorage.setItem(key, JSON.stringify(authData));
@@ -23,8 +30,13 @@ test.describe("Authentication", () => {
// 2. High-priority Mocks
await page.route("**/api/v1/user/me", async (route) => {
await route.fulfill({
json: { id: "admin-user", name: "Admin", role: "super_admin", manageableTenants: [] },
headers: { 'Access-Control-Allow-Origin': '*' }
json: {
id: "admin-user",
name: "Admin",
role: "super_admin",
manageableTenants: [],
},
headers: { "Access-Control-Allow-Origin": "*" },
});
});
@@ -40,15 +52,19 @@ test.describe("Authentication", () => {
userinfo_endpoint: "http://localhost:5000/oidc/userinfo",
end_session_endpoint: "http://localhost:5000/oidc/session/end",
},
headers: { 'Access-Control-Allow-Origin': '*' }
headers: { "Access-Control-Allow-Origin": "*" },
});
} else if (url.includes("/jwks")) {
await route.fulfill({
json: { keys: [] },
headers: { 'Access-Control-Allow-Origin': '*' }
headers: { "Access-Control-Allow-Origin": "*" },
});
} else {
await route.fulfill({ status: 200, body: "ok", headers: { 'Access-Control-Allow-Origin': '*' } });
await route.fulfill({
status: 200,
body: "ok",
headers: { "Access-Control-Allow-Origin": "*" },
});
}
});
@@ -65,23 +81,33 @@ test.describe("Authentication", () => {
test("should redirect unauthorized users to login page", async ({ page }) => {
await page.addInitScript(() => {
window.localStorage.clear();
(window as any)._IS_TEST_MODE = false;
(
window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean }
)._IS_TEST_MODE = false;
});
await page.goto("/");
await expect(page).toHaveURL(/.*\/login.*/, { timeout: 15000 });
});
test("should allow access to dashboard when authenticated", async ({ page }) => {
test("should allow access to dashboard when authenticated", async ({
page,
}) => {
await page.goto("/");
// strict mode violation 피하기 위해 .last() 사용하거나 더 구체적인 셀렉터 사용
await expect(page.locator("h1").last()).toContainText(/Admin Control|운영 도구/i, { timeout: 15000 });
await expect(page.locator("h1").last()).toContainText(
/Admin Control|운영 도구/i,
{ timeout: 15000 },
);
});
test("should logout and redirect to login page", async ({ page }) => {
await page.goto("/");
page.on("dialog", (dialog) => dialog.accept());
const logoutBtn = page.locator('button').filter({ hasText: /Logout|로그아웃/i }).first();
await logoutBtn.waitFor({ state: 'visible' });
const logoutBtn = page
.locator("button")
.filter({ hasText: /Logout|로그아웃/i })
.first();
await logoutBtn.waitFor({ state: "visible" });
await logoutBtn.click();
await expect(page).toHaveURL(/.*\/login.*/, { timeout: 15000 });
});

View File

@@ -5,8 +5,10 @@ test.describe("Bulk Actions and Tree Search", () => {
await page.addInitScript(() => {
window.localStorage.setItem("locale", "ko");
window.localStorage.setItem("admin_session", "fake-token");
(window as any)._IS_TEST_MODE = true;
(
window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean }
)._IS_TEST_MODE = true;
const authority = "http://localhost:5000/oidc";
const client_id = "adminfront";
const key = `oidc.user:${authority}:${client_id}`;
@@ -22,24 +24,43 @@ test.describe("Bulk Actions and Tree Search", () => {
// Capture ALL API calls to our mock host
await page.route("**/api/v1/**", async (route) => {
const url = route.request().url();
const headers = { 'Access-Control-Allow-Origin': '*' };
const headers = { "Access-Control-Allow-Origin": "*" };
if (url.includes("/user/me")) {
return route.fulfill({
json: { id: "admin", role: "super_admin", name: "Admin", manageableTenants: [] },
headers
json: {
id: "admin",
role: "super_admin",
name: "Admin",
manageableTenants: [],
},
headers,
});
}
if (url.includes("/admin/users")) {
return route.fulfill({
json: {
items: [
{ id: "u-1", name: "User One", email: "u1@test.com", status: "active", role: "user", createdAt: new Date().toISOString() },
{ id: "u-2", name: "User Two", email: "u2@test.com", status: "active", role: "user", createdAt: new Date().toISOString() },
{
id: "u-1",
name: "User One",
email: "u1@test.com",
status: "active",
role: "user",
createdAt: new Date().toISOString(),
},
{
id: "u-2",
name: "User Two",
email: "u2@test.com",
status: "active",
role: "user",
createdAt: new Date().toISOString(),
},
],
total: 2,
},
headers
headers,
});
}
if (url.includes("/organization")) {
@@ -48,22 +69,31 @@ test.describe("Bulk Actions and Tree Search", () => {
{ id: "g-1", name: "Engineering", slug: "eng", tenantId: "t-1" },
{ id: "g-2", name: "Sales", slug: "sales", tenantId: "t-1" },
],
headers
headers,
});
}
if (url.includes("/admin/tenants/t-1")) {
return route.fulfill({
json: { id: "t-1", name: "Main Tenant", slug: "main", status: "active", type: "COMPANY" },
headers
json: {
id: "t-1",
name: "Main Tenant",
slug: "main",
status: "active",
type: "COMPANY",
},
headers,
});
}
if (url.includes("/admin/tenants")) {
return route.fulfill({
json: { items: [{ id: "t-1", name: "Main Tenant", slug: "main" }], total: 1 },
headers
json: {
items: [{ id: "t-1", name: "Main Tenant", slug: "main" }],
total: 1,
},
headers,
});
}
return route.fulfill({ json: { items: [], total: 0 }, headers });
});
@@ -72,12 +102,14 @@ test.describe("Bulk Actions and Tree Search", () => {
});
});
test("should show bulk action bar when users are selected", async ({ page }) => {
test("should show bulk action bar when users are selected", async ({
page,
}) => {
await page.goto("/users");
// 로딩바 대기 대신 실제 데이터 텍스트 대기
const table = page.locator("table");
await expect(table).toContainText("User One", { timeout: 20000 });
// 첫 번째 데이터의 체크박스 선택
const userCheckbox = page.locator('table input[type="checkbox"]').nth(1);
await userCheckbox.click();
@@ -85,7 +117,7 @@ test.describe("Bulk Actions and Tree Search", () => {
// 일괄 작업 바 확인
const selectionBar = page.getByTestId("bulk-action-bar");
await expect(selectionBar).toBeVisible({ timeout: 15000 });
// 활성화 버튼 확인
const activeBtn = page.getByTestId("bulk-active-btn");
await expect(activeBtn).toBeVisible({ timeout: 10000 });
@@ -97,25 +129,38 @@ test.describe("Bulk Actions and Tree Search", () => {
// 선택 해제 버튼
const closeBtn = page.getByTestId("bulk-close-btn");
await closeBtn.click();
await expect(selectionBar).not.toBeVisible({ timeout: 10000 });
});
test("should filter and highlight nodes in organization tree", async ({ page }) => {
test("should filter and highlight nodes in organization tree", async ({
page,
}) => {
await page.goto("/tenants/t-1");
// 테넌트 이름이 제목으로 나올 때까지 대기
await expect(page.locator("h2").last()).toContainText(/Main Tenant|상세|Profile/i, { timeout: 20000 });
await expect(page.locator("h2").last()).toContainText(
/Main Tenant|상세|Profile/i,
{ timeout: 20000 },
);
const subTenantLink = page.locator('a, button').filter({ hasText: /조직 관리|Organization|Sub-tenant/i }).first();
const subTenantLink = page
.locator("a, button")
.filter({ hasText: /조직 관리|Organization|Sub-tenant/i })
.first();
await subTenantLink.click();
// 트리 검색 입력창 대기 (더 유연한 셀렉터)
const searchInput = page.locator('input[placeholder*="검색"], input[placeholder*="Search"]').first();
const searchInput = page
.locator('input[placeholder*="검색"], input[placeholder*="Search"]')
.first();
await expect(searchInput).toBeVisible({ timeout: 15000 });
await searchInput.fill("Eng");
const engRow = page.locator('tr').filter({ hasText: "Engineering" }).first();
const engRow = page
.locator("tr")
.filter({ hasText: "Engineering" })
.first();
await expect(engRow).toBeVisible();
await expect(engRow).toHaveClass(/bg-primary/);
});

View File

@@ -20,7 +20,9 @@ test.describe("Tenant Owners Management", () => {
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;
(
window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean }
)._IS_TEST_MODE = true;
});
await page.route("**/oidc/**", async (route) => {
@@ -29,7 +31,8 @@ test.describe("Tenant Owners Management", () => {
await page.route(/.*\/api\/v1\/.*/, async (route) => {
const url = route.request().url();
if (url.includes("/user/me")) { console.log("Mocking ME");
if (url.includes("/user/me")) {
console.log("Mocking ME");
return route.fulfill({
json: {
id: "admin-user",
@@ -85,27 +88,39 @@ test.describe("Tenant Owners Management", () => {
await expect(page.getByText(/테넌트 소유자|Tenant Owners/)).toBeVisible();
await expect(page.locator("table").first()).toContainText("Owner One");
await expect(page.locator("table").first()).toContainText("owner1@example.com");
await expect(page.locator("table").first()).toContainText(
"owner1@example.com",
);
});
test("should add a new owner", async ({ page }) => {
// Specific override for this test
await page.route("**/api/v1/admin/tenants/tenant-1/owners", async (route) => {
if (route.request().method() === "GET") {
await route.fulfill({ json: [] });
} else {
await route.fulfill({ status: 200, json: {} });
}
});
await page.route(
"**/api/v1/admin/tenants/tenant-1/owners",
async (route) => {
if (route.request().method() === "GET") {
await route.fulfill({ json: [] });
} else {
await route.fulfill({ status: 200, json: {} });
}
},
);
await page.goto("/tenants/tenant-1/permissions");
await page.waitForLoadState("networkidle");
await expect(page.locator(".animate-spin").first()).not.toBeVisible();
await page.click('button:has-text("소유자 추가"), button:has-text("Add Owner")');
await page.fill('input[placeholder*="사용자 검색"], input[placeholder*="Search users"]', "User Two");
await page.click(
'button:has-text("소유자 추가"), button:has-text("Add Owner")',
);
await page.fill(
'input[placeholder*="사용자 검색"], input[placeholder*="Search users"]',
"User Two",
);
const addButton = page.locator("role=dialog").getByRole("button", { name: /추가|Add/ });
const addButton = page
.locator("role=dialog")
.getByRole("button", { name: /추가|Add/ });
await addButton.click();
});
});

View File

@@ -5,8 +5,10 @@ test.describe("Tenants Management", () => {
await page.addInitScript(() => {
window.localStorage.setItem("locale", "ko");
window.localStorage.setItem("admin_session", "fake-token");
(window as any)._IS_TEST_MODE = true;
(
window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean }
)._IS_TEST_MODE = true;
const authority = "http://localhost:5000/oidc";
const client_id = "adminfront";
const key = `oidc.user:${authority}:${client_id}`;
@@ -21,19 +23,28 @@ test.describe("Tenants Management", () => {
await page.route("**/api/v1/**", async (route) => {
const url = route.request().url();
const headers = { 'Access-Control-Allow-Origin': '*' };
const headers = { "Access-Control-Allow-Origin": "*" };
if (url.includes("/user/me")) {
return route.fulfill({
json: { id: "admin-user", name: "Admin", role: "super_admin", manageableTenants: [] },
headers
json: {
id: "admin-user",
name: "Admin",
role: "super_admin",
manageableTenants: [],
},
headers,
});
}
if (url.includes("/admin/tenants")) {
if (route.request().method() === "GET" && !url.includes("/parent-1") && !url.includes("/organization")) {
if (
route.request().method() === "GET" &&
!url.includes("/parent-1") &&
!url.includes("/organization")
) {
return route.fulfill({
json: { items: [], total: 0, limit: 100, offset: 0 },
headers
headers,
});
}
}
@@ -50,10 +61,21 @@ test.describe("Tenants Management", () => {
if (route.request().method() === "GET") {
await route.fulfill({
json: {
items: [{ id: "1", name: "Tenant A", slug: "tenant-a", status: "active", type: "COMPANY", updatedAt: new Date().toISOString() }],
total: 1, limit: 1000, offset: 0,
items: [
{
id: "1",
name: "Tenant A",
slug: "tenant-a",
status: "active",
type: "COMPANY",
updatedAt: new Date().toISOString(),
},
],
total: 1,
limit: 1000,
offset: 0,
},
headers: { 'Access-Control-Allow-Origin': '*' }
headers: { "Access-Control-Allow-Origin": "*" },
});
} else {
await route.continue();
@@ -61,67 +83,119 @@ test.describe("Tenants Management", () => {
});
await page.goto("/tenants");
await expect(page.locator("h2").last()).toContainText(/테넌트 목록|Tenants/i, { timeout: 20000 });
await expect(page.locator("table")).toContainText("Tenant A", { timeout: 10000 });
await expect(page.locator("h2").last()).toContainText(
/테넌트 목록|Tenants/i,
{ timeout: 20000 },
);
await expect(page.locator("table")).toContainText("Tenant A", {
timeout: 10000,
});
});
test("should create a new tenant", async ({ page }) => {
await page.goto("/tenants/new");
await expect(page.locator("h2").last()).toContainText(/추가|Create/i, { timeout: 20000 });
await expect(page.locator("h2").last()).toContainText(/추가|Create/i, {
timeout: 20000,
});
const nameInput = page.locator('input[name="name"]').first();
await nameInput.fill("New Tenant");
const slugInput = page.locator('input[name="slug"]').first();
await slugInput.fill("new-tenant");
await page.locator("textarea").first().fill("Description");
const submitBtn = page.locator('button').filter({ hasText: /생성|Create/i }).first();
const submitBtn = page
.locator("button")
.filter({ hasText: /생성|Create/i })
.first();
await submitBtn.click();
await expect(page).toHaveURL(/.*\/tenants$/, { timeout: 15000 });
});
test("should show validation error on empty name", async ({ page }) => {
await page.goto("/tenants/new");
await expect(page.locator("h2").last()).toContainText(/추가|Create/i, { timeout: 20000 });
await expect(page.locator("h2").last()).toContainText(/추가|Create/i, {
timeout: 20000,
});
const submitBtn = page.locator('button').filter({ hasText: /생성|Create/i }).first();
const submitBtn = page
.locator("button")
.filter({ hasText: /생성|Create/i })
.first();
await expect(submitBtn).toBeDisabled();
await page.locator('input[name="name"]').first().fill("Valid Name");
await expect(submitBtn).not.toBeDisabled();
});
test("should show organization hierarchy and member list distinction", async ({ page }) => {
test("should show organization hierarchy and member list distinction", async ({
page,
}) => {
const mockTenants = [
{ id: "parent-1", name: "Parent Org", slug: "parent-slug", status: "active", type: "COMPANY", memberCount: 5, parentId: null },
{ id: "child-1", name: "Child Team", slug: "child-slug", status: "active", type: "USER_GROUP", memberCount: 3, parentId: "parent-1" },
{
id: "parent-1",
name: "Parent Org",
slug: "parent-slug",
status: "active",
type: "COMPANY",
memberCount: 5,
parentId: null,
},
{
id: "child-1",
name: "Child Team",
slug: "child-slug",
status: "active",
type: "USER_GROUP",
memberCount: 3,
parentId: "parent-1",
},
];
await page.route("**/api/v1/admin/tenants**", async (route) => {
const url = route.request().url();
if (url.includes("/organization")) {
await route.fulfill({ json: mockTenants, headers: { 'Access-Control-Allow-Origin': '*' } });
await route.fulfill({
json: mockTenants,
headers: { "Access-Control-Allow-Origin": "*" },
});
} else if (url.includes("/parent-1")) {
await route.fulfill({ json: mockTenants[0], headers: { 'Access-Control-Allow-Origin': '*' } });
await route.fulfill({
json: mockTenants[0],
headers: { "Access-Control-Allow-Origin": "*" },
});
} else {
await route.fulfill({
json: { items: mockTenants, total: 2, limit: 1000, offset: 0 },
headers: { 'Access-Control-Allow-Origin': '*' }
headers: { "Access-Control-Allow-Origin": "*" },
});
}
});
await page.goto("/tenants/parent-1/organization");
await expect(page.locator("table")).toContainText("Parent Org", { timeout: 20000 });
await expect(page.locator("table")).toContainText("Parent Org", {
timeout: 20000,
});
const parentRow = page.locator('tr').filter({ hasText: "Parent Org" }).first();
await expect(parentRow).toContainText("5");
const parentRow = page
.locator("tr")
.filter({ hasText: "Parent Org" })
.first();
await expect(parentRow).toContainText("5");
const memberButton = parentRow.getByRole("button").filter({ hasText: /Direct|소속|직속/ }).first();
const memberButton = parentRow
.getByRole("button")
.filter({ hasText: /Direct|소속|직속/ })
.first();
await memberButton.click();
await expect(page.locator('button[role="tab"]').filter({ hasText: /소속 멤버|Direct Members/i }).first()).toBeVisible();
await expect(
page
.locator('button[role="tab"]')
.filter({ hasText: /소속 멤버|Direct Members/i })
.first(),
).toBeVisible();
});
});

View File

@@ -5,8 +5,10 @@ test.describe("Users Bulk Upload", () => {
await page.addInitScript(() => {
window.localStorage.setItem("locale", "ko");
window.localStorage.setItem("admin_session", "fake-token");
(window as any)._IS_TEST_MODE = true;
(
window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean }
)._IS_TEST_MODE = true;
const authority = "http://localhost:5000/oidc";
const client_id = "adminfront";
const key = `oidc.user:${authority}:${client_id}`;
@@ -21,21 +23,32 @@ test.describe("Users Bulk Upload", () => {
await page.route("**/api/v1/**", async (route) => {
const url = route.request().url();
const headers = { 'Access-Control-Allow-Origin': '*' };
const headers = { "Access-Control-Allow-Origin": "*" };
if (url.includes("/user/me")) {
return route.fulfill({
json: { id: "admin-user", name: "Admin", role: "super_admin", manageableTenants: [] },
headers
json: {
id: "admin-user",
name: "Admin",
role: "super_admin",
manageableTenants: [],
},
headers,
});
}
if (url.includes("/admin/users")) {
if (!url.includes("/bulk")) {
return route.fulfill({ json: { items: [], total: 0, limit: 50, offset: 0 }, headers });
return route.fulfill({
json: { items: [], total: 0, limit: 50, offset: 0 },
headers,
});
}
}
if (url.includes("/admin/tenants")) {
return route.fulfill({ json: { items: [], total: 0, limit: 100, offset: 0 }, headers });
return route.fulfill({
json: { items: [], total: 0, limit: 100, offset: 0 },
headers,
});
}
return route.fulfill({ json: { items: [], total: 0 }, headers });
});
@@ -48,13 +61,21 @@ test.describe("Users Bulk Upload", () => {
test("should open bulk upload modal and show preview", async ({ page }) => {
await page.goto("/users");
// 헤더 타이틀이 뜰 때까지 대기
await expect(page.getByTestId("page-title")).toContainText(/사용자|Users/i, { timeout: 20000 });
await expect(page.getByTestId("page-title")).toContainText(
/사용자|Users/i,
{ timeout: 20000 },
);
const bulkBtn = page.getByTestId("bulk-import-btn");
await bulkBtn.click();
await expect(page.getByTestId("bulk-upload-title")).toBeVisible({ timeout: 10000 });
const downloadBtn = page.locator('button').filter({ hasText: /템플릿 다운로드|템플릿 받기|Download Template/ }).first();
await expect(page.getByTestId("bulk-upload-title")).toBeVisible({
timeout: 10000,
});
const downloadBtn = page
.locator("button")
.filter({ hasText: /템플릿 다운로드|템플릿 받기|Download Template/ })
.first();
await expect(downloadBtn).toBeVisible();
});
@@ -65,10 +86,14 @@ test.describe("Users Bulk Upload", () => {
json: {
results: [
{ email: "success@test.com", success: true, userId: "u-1" },
{ email: "fail@test.com", success: false, message: "Invalid format" },
{
email: "fail@test.com",
success: false,
message: "Invalid format",
},
],
},
headers: { 'Access-Control-Allow-Origin': '*' }
headers: { "Access-Control-Allow-Origin": "*" },
});
} else {
await route.continue();
@@ -76,11 +101,14 @@ test.describe("Users Bulk Upload", () => {
});
await page.goto("/users");
await expect(page.getByTestId("page-title")).toContainText(/사용자|Users/i, { timeout: 20000 });
await expect(page.getByTestId("page-title")).toContainText(
/사용자|Users/i,
{ timeout: 20000 },
);
const bulkBtn = page.getByTestId("bulk-import-btn");
await bulkBtn.click();
const uploadBtn = page.getByTestId("bulk-start-btn");
await expect(uploadBtn).toBeDisabled();
});

View File

@@ -15,7 +15,9 @@ test.describe("User Schema Dynamic Form", () => {
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;
(
window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean }
)._IS_TEST_MODE = true;
});
await page.route("**/oidc/**", async (route) => {
@@ -24,20 +26,38 @@ test.describe("User Schema Dynamic Form", () => {
await page.route(/.*\/api\/v1\/.*/, async (route) => {
const url = route.request().url();
if (url.includes("/user/me")) { console.log("Mocking ME");
if (url.includes("/user/me")) {
console.log("Mocking ME");
return route.fulfill({
json: { id: "admin-user", name: "Admin", role: "super_admin", manageableTenants: [] },
json: {
id: "admin-user",
name: "Admin",
role: "super_admin",
manageableTenants: [],
},
});
}
if (url.includes("/admin/tenants/t-1")) {
return route.fulfill({
json: {
id: "t-1", name: "Test Tenant", slug: "test-tenant",
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" },
{
key: "emp_id",
label: "Employee ID",
required: true,
validation: "^E[0-9]{3}$",
},
{
key: "salary",
label: "Salary",
adminOnly: true,
type: "number",
},
],
},
},
@@ -47,9 +67,14 @@ test.describe("User Schema Dynamic Form", () => {
if (url.includes("/admin/users/u-1")) {
return route.fulfill({
json: {
id: "u-1", name: "John Doe", email: "john@test.com", companyCode: "test-tenant",
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" }],
joinedTenants: [
{ id: "t-1", name: "Test Tenant", slug: "test-tenant" },
],
metadata: { "t-1": { emp_id: "E123", salary: 1000 } },
},
});
@@ -57,7 +82,10 @@ test.describe("User Schema Dynamic Form", () => {
if (url.includes("/admin/tenants")) {
return route.fulfill({
json: { items: [{ id: "t-1", slug: "test-tenant", name: "Test Tenant" }], total: 1 },
json: {
items: [{ id: "t-1", slug: "test-tenant", name: "Test Tenant" }],
total: 1,
},
});
}
@@ -65,40 +93,48 @@ test.describe("User Schema Dynamic Form", () => {
});
});
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");
// 섹션 헤더 확인
const header = page.getByText(/테넌트별 프로필 관리|Per-tenant Profile/i).first();
await header.waitFor({ state: 'visible' });
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.locator('input[id*="emp_id"]');
await empIdInput.waitFor({ state: 'visible' });
await empIdInput.waitFor({ state: "visible" });
await empIdInput.fill("invalid");
// 포커스 해제하여 유효성 검사 트리거
await page.getByLabel(/이름|Name/i).click();
// 에러 메시지 확인
const errorMsg = page.locator('form').getByText(/Employee ID|필수|invalid|format/i);
const errorMsg = page
.locator("form")
.getByText(/Employee ID|필수|invalid|format/i);
await expect(errorMsg).toBeVisible();
});
});

View File

@@ -77,7 +77,6 @@ func (h *UserHandler) ListUsers(c *fiber.Ctx) error {
var requesterRole string
if profile, ok := c.Locals("user_profile").(*domain.UserProfileResponse); ok {
requesterRole = domain.NormalizeRole(profile.Role)
requesterCompany = profile.CompanyCode
}
limit := c.QueryInt("limit", 50)

View File

@@ -1,34 +1,8 @@
import { expect, test } from "@playwright/test";
import { seedAuth } from "./helpers/devfront-fixtures";
test("clients page loads correctly", async ({ page }) => {
const nowInSeconds = Math.floor(Date.now() / 1000);
await page.addInitScript((issuedAt) => {
const mockOidcUser = {
id_token: "playwright-id-token",
session_state: "playwright-session",
access_token: "playwright-access-token",
refresh_token: "playwright-refresh-token",
token_type: "Bearer",
scope: "openid profile email",
profile: {
sub: "playwright-user",
email: "playwright@example.com",
name: "Playwright User",
},
expires_at: issuedAt + 3600,
};
// oidc-client-ts storage key format: oidc.user:{authority}:{client_id}
window.localStorage.setItem(
"oidc.user:http://localhost:5000/oidc:devfront",
JSON.stringify(mockOidcUser),
);
window.localStorage.setItem(
"oidc.user:http://localhost:5000/oidc/:devfront",
JSON.stringify(mockOidcUser),
);
}, nowInSeconds);
await seedAuth(page);
await page.route("**/api/v1/dev/clients**", async (route) => {
if (route.request().method() !== "GET") {

View File

@@ -103,6 +103,31 @@ export async function seedAuth(page: Page, role?: string) {
},
{ issuedAt: nowInSeconds, injectedRole: role ?? "" },
);
await page.route("**/oidc/**", async (route) => {
const url = route.request().url();
if (url.includes(".well-known/openid-configuration")) {
await route.fulfill({
json: {
issuer: "http://localhost:5000/oidc",
authorization_endpoint: "http://localhost:5000/oidc/auth",
token_endpoint: "http://localhost:5000/oidc/token",
jwks_uri: "http://localhost:5000/oidc/jwks",
userinfo_endpoint: "http://localhost:5000/oidc/userinfo",
end_session_endpoint: "http://localhost:5000/oidc/session/end",
},
headers: { "Access-Control-Allow-Origin": "*" },
});
} else if (url.includes("/jwks")) {
await route.fulfill({
json: { keys: [] },
headers: { "Access-Control-Allow-Origin": "*" },
});
} else {
await route.fulfill({ status: 200, body: "ok", headers: { "Access-Control-Allow-Origin": "*" } });
}
});
}
function json(route: Route, payload: unknown, status = 200) {