1
0
forked from baron/baron-sso
Files
baron-sso/adminfront/tests/users_bulk.spec.ts

88 lines
3.2 KiB
TypeScript

import { expect, test } from "@playwright/test";
test.describe("Users Bulk Upload", () => {
test.beforeEach(async ({ page }) => {
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", role: "super_admin" },
expires_at: Math.floor(Date.now() / 1000) + 36000,
};
window.localStorage.setItem(key, JSON.stringify(authData));
});
await page.route("**/api/v1/**", async (route) => {
const url = route.request().url();
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
});
}
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 });
});
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.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(downloadBtn).toBeVisible();
});
test("should show success results after mock upload", async ({ page }) => {
await page.route("**/api/v1/admin/users/bulk", async (route) => {
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 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();
});
});