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("Tenant Owners Management", () => {
test.beforeEach(async ({ page }) => {
// Authenticate
await page.addInitScript(() => {
const authority = "http://localhost:5000/oidc";
const client_id = "adminfront";
@@ -14,126 +13,99 @@ test.describe("Tenant Owners Management", () => {
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));
});
// Mock OIDC config to avoid redirects
await page.route(
"**/oidc/.well-known/openid-configuration",
async (route) => {
await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } });
},
);
// Mock user profile
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",
},
});
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;
});
// Mock tenant details
await page.route("**/api/v1/admin/tenants/tenant-1**", async (route) => {
await route.fulfill({
json: {
id: "tenant-1",
name: "Test Tenant",
slug: "test-tenant",
status: "active",
type: "COMPANY",
},
});
await page.route("**/oidc/**", async (route) => {
await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } });
});
});
test("should list tenant owners", async ({ page }) => {
// Mock owners list
await page.route(
"**/api/v1/admin/tenants/tenant-1/owners**",
async (route) => {
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 User",
email: "admin@example.com",
role: "super_admin",
manageableTenants: [],
},
});
}
if (url.includes("/owners")) {
return route.fulfill({
json: [
{ id: "owner-1", name: "Owner One", email: "owner1@example.com" },
],
});
},
);
// Mock admins list (empty)
await page.route(
"**/api/v1/admin/tenants/tenant-1/admins**",
async (route) => {
await route.fulfill({ json: [] });
},
);
}
if (url.includes("/admins")) {
return route.fulfill({ json: [] });
}
if (url.includes("/admin/tenants/tenant-1")) {
return route.fulfill({
json: {
id: "tenant-1",
name: "Test Tenant",
slug: "test-tenant",
status: "active",
type: "COMPANY",
},
});
}
if (url.includes("/admin/users") && route.request().method() === "GET") {
return route.fulfill({
json: {
items: [
{ id: "user-2", name: "User Two", email: "user2@example.com" },
],
total: 1,
},
});
}
if (route.request().method() === "GET") {
return route.fulfill({ json: { items: [], total: 0 } });
}
return route.fulfill({ status: 200, json: {} });
});
});
test("should list tenant owners", async ({ page }) => {
await page.goto("/tenants/tenant-1/permissions");
await page.waitForLoadState("networkidle");
await expect(page.locator(".animate-spin").first()).not.toBeVisible();
// Check if the page title and the owner are visible
await expect(page.getByText("테넌트 소유자")).toBeVisible();
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 }) => {
// Mock owners list (initially empty)
await page.route(
"**/api/v1/admin/tenants/tenant-1/owners**",
async (route) => {
if (route.request().method() === "GET") {
await route.fulfill({ json: [] });
} else if (route.request().method() === "POST") {
await route.fulfill({ status: 200 });
}
},
);
// Mock admins list (empty)
await page.route(
"**/api/v1/admin/tenants/tenant-1/admins**",
async (route) => {
// 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: [] });
},
);
// Mock users search
await page.route("**/api/v1/admin/users?**", async (route) => {
await route.fulfill({
json: {
items: [
{ id: "user-2", name: "User Two", email: "user2@example.com" },
],
total: 1,
},
});
} 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();
// Click add button
await page.click('button:has-text("소유자 추가")');
await page.click('button:has-text("소유자 추가"), button:has-text("Add Owner")');
await page.fill('input[placeholder*="사용자 검색"], input[placeholder*="Search users"]', "User Two");
// Search for user
await page.fill('input[placeholder*="사용자 검색"]', "User Two");
// Wait for results and add - using a more specific selector to target the button in the dialog
const addButton = page
.locator("role=dialog")
.getByRole("button", { name: "추가" });
const addButton = page.locator("role=dialog").getByRole("button", { name: /추가|Add/ });
await addButton.click();
// Verify toast or mutation (in a real app, the list would refresh)
// Here we just check if the dialog was closed or toast appears
// toast is shown on success
});
});