forked from baron/baron-sso
폼 선택자(Form Selector) 안정화, 다국어 번역 키 불일치 수정, 컴포넌트 테스트 용이성(Testability) 개선, Strict Mode 위반 해결, OIDC 모킹(Mocking) 강화
This commit is contained in:
@@ -2,94 +2,86 @@ import { expect, test } from "@playwright/test";
|
||||
|
||||
test.describe("Users Bulk Upload", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Authenticate
|
||||
await page.addInitScript(() => {
|
||||
window.localStorage.setItem("locale", "ko");
|
||||
window.localStorage.setItem("admin_session", "fake-token");
|
||||
(window as any)._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 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));
|
||||
});
|
||||
|
||||
// Mock OIDC config
|
||||
await page.route(
|
||||
"**/oidc/.well-known/openid-configuration",
|
||||
async (route) => {
|
||||
await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } });
|
||||
},
|
||||
);
|
||||
await page.route("**/api/v1/**", async (route) => {
|
||||
const url = route.request().url();
|
||||
const headers = { 'Access-Control-Allow-Origin': '*' };
|
||||
|
||||
// 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",
|
||||
},
|
||||
});
|
||||
if (url.includes("/user/me")) {
|
||||
return route.fulfill({
|
||||
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 });
|
||||
}
|
||||
}
|
||||
if (url.includes("/admin/tenants")) {
|
||||
return route.fulfill({ json: { items: [], total: 0, limit: 100, offset: 0 }, headers });
|
||||
}
|
||||
return route.fulfill({ json: { items: [], total: 0 }, headers });
|
||||
});
|
||||
|
||||
// Mock users list
|
||||
await page.route("**/api/v1/admin/users?*", async (route) => {
|
||||
await route.fulfill({
|
||||
json: { items: [], total: 0, limit: 50, offset: 0 },
|
||||
});
|
||||
await page.route("**/oidc/**", async (route) => {
|
||||
await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } });
|
||||
});
|
||||
});
|
||||
|
||||
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 });
|
||||
|
||||
const bulkBtn = page.getByRole("button", {
|
||||
name: /일괄 등록|Bulk Import/i,
|
||||
});
|
||||
await expect(bulkBtn).toBeVisible();
|
||||
const bulkBtn = page.getByTestId("bulk-import-btn");
|
||||
await bulkBtn.click();
|
||||
|
||||
await expect(
|
||||
page.getByText(/사용자 일괄 등록|User Bulk Upload/i),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.getByRole("button", { name: /템플릿 다운로드|Download Template/i }),
|
||||
).toBeVisible();
|
||||
await expect(page.getByTestId("bulk-upload-title")).toBeVisible({ timeout: 10000 });
|
||||
const downloadBtn = page.locator('button').filter({ hasText: /템플릿 다운로드|템플릿 받기|Download Template/ }).first();
|
||||
await expect(downloadBtn).toBeVisible();
|
||||
});
|
||||
|
||||
test("should show success results after mock upload", async ({ page }) => {
|
||||
// Mock bulk API response
|
||||
await page.route("**/api/v1/admin/users/bulk", async (route) => {
|
||||
await route.fulfill({
|
||||
json: {
|
||||
results: [
|
||||
{ email: "success@test.com", success: true, userId: "u-1" },
|
||||
{
|
||||
email: "fail@test.com",
|
||||
success: false,
|
||||
message: "Invalid format",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
if (route.request().method() === "POST") {
|
||||
await route.fulfill({
|
||||
json: {
|
||||
results: [
|
||||
{ email: "success@test.com", success: true, userId: "u-1" },
|
||||
{ email: "fail@test.com", success: false, message: "Invalid format" },
|
||||
],
|
||||
},
|
||||
headers: { 'Access-Control-Allow-Origin': '*' }
|
||||
});
|
||||
} else {
|
||||
await route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
await page.goto("/users");
|
||||
await page.getByRole("button", { name: /일괄 등록|Bulk Import/i }).click();
|
||||
await expect(page.getByTestId("page-title")).toContainText(/사용자|Users/i, { timeout: 20000 });
|
||||
|
||||
// Directly set internal state for testing results view if file simulation is hard
|
||||
// But let's assume we want to see the "Start Upload" button disabled initially
|
||||
const uploadBtn = page.getByRole("button", {
|
||||
name: /등록 시작|Start Upload/i,
|
||||
});
|
||||
const bulkBtn = page.getByTestId("bulk-import-btn");
|
||||
await bulkBtn.click();
|
||||
|
||||
const uploadBtn = page.getByTestId("bulk-start-btn");
|
||||
await expect(uploadBtn).toBeDisabled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user