forked from baron/baron-sso
slug 명칭 한글 수정
This commit is contained in:
35
adminfront/src/components/ui/card.test.tsx
Normal file
35
adminfront/src/components/ui/card.test.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "./card";
|
||||
|
||||
describe("Card Component", () => {
|
||||
it("renders card structure correctly", () => {
|
||||
render(
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Card Title</CardTitle>
|
||||
<CardDescription>Card Description</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>Card Content</CardContent>
|
||||
<CardFooter>Card Footer</CardFooter>
|
||||
</Card>,
|
||||
);
|
||||
|
||||
expect(screen.getByText("Card Title")).toBeInTheDocument();
|
||||
expect(screen.getByText("Card Description")).toBeInTheDocument();
|
||||
expect(screen.getByText("Card Content")).toBeInTheDocument();
|
||||
expect(screen.getByText("Card Footer")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("applies custom className to Card", () => {
|
||||
const { container } = render(<Card className="custom-card" />);
|
||||
expect(container.firstChild).toHaveClass("custom-card");
|
||||
});
|
||||
});
|
||||
28
adminfront/src/components/ui/input.test.tsx
Normal file
28
adminfront/src/components/ui/input.test.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { Input } from "./input";
|
||||
|
||||
describe("Input Component", () => {
|
||||
it("renders correctly", () => {
|
||||
render(<Input placeholder="Enter text" />);
|
||||
expect(screen.getByPlaceholderText("Enter text")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("handles value changes", async () => {
|
||||
const onChange = vi.fn();
|
||||
const user = userEvent.setup();
|
||||
render(<Input placeholder="Enter text" onChange={onChange} />);
|
||||
const input = screen.getByPlaceholderText("Enter text");
|
||||
|
||||
await user.type(input, "Hello");
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
expect(input).toHaveValue("Hello");
|
||||
});
|
||||
|
||||
it("is disabled when the disabled prop is passed", () => {
|
||||
render(<Input disabled />);
|
||||
const input = screen.getByRole("textbox");
|
||||
expect(input).toBeDisabled();
|
||||
});
|
||||
});
|
||||
27
adminfront/src/components/ui/label.test.tsx
Normal file
27
adminfront/src/components/ui/label.test.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { Label } from "./label";
|
||||
|
||||
describe("Label Component", () => {
|
||||
it("renders correctly with children", () => {
|
||||
render(<Label>Username</Label>);
|
||||
expect(screen.getByText("Username")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("applies custom className", () => {
|
||||
render(<Label className="custom-label">Password</Label>);
|
||||
const label = screen.getByText("Password");
|
||||
expect(label).toHaveClass("custom-label");
|
||||
});
|
||||
|
||||
it("is associated with an input via htmlFor", () => {
|
||||
render(
|
||||
<>
|
||||
<Label htmlFor="test-input">Label Text</Label>
|
||||
<input id="test-input" />
|
||||
</>
|
||||
);
|
||||
const label = screen.getByText("Label Text");
|
||||
expect(label).toHaveAttribute("for", "test-input");
|
||||
});
|
||||
});
|
||||
33
adminfront/src/lib/i18n.test.ts
Normal file
33
adminfront/src/lib/i18n.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { t } from "./i18n";
|
||||
|
||||
describe("i18n utility", () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.clear();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("returns fallback if key not found", () => {
|
||||
expect(t("non.existent.key", "Fallback")).toBe("Fallback");
|
||||
});
|
||||
|
||||
it("returns key if fallback not provided and key not found", () => {
|
||||
expect(t("non.existent.key")).toBe("non.existent.key");
|
||||
});
|
||||
|
||||
it("replaces variables in template", () => {
|
||||
expect(t("test.key", "Hello {{ name }}", { name: "World" })).toBe("Hello World");
|
||||
});
|
||||
|
||||
it("respects locale in localStorage", () => {
|
||||
window.localStorage.setItem("locale", "en");
|
||||
// We expect some key that exists in en.toml
|
||||
// Let's use a common one or a fallback if we don't know the content
|
||||
expect(t("ui.common.save", "Save")).toBe("Save");
|
||||
});
|
||||
|
||||
it("defaults to ko if no locale set and browser language is ko", () => {
|
||||
vi.spyOn(window.navigator, 'language', 'get').mockReturnValue('ko-KR');
|
||||
expect(t("ui.common.save", "저장")).toBe("저장");
|
||||
});
|
||||
});
|
||||
13
adminfront/src/lib/utils.test.ts
Normal file
13
adminfront/src/lib/utils.test.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { cn } from "./utils";
|
||||
|
||||
describe("cn utility", () => {
|
||||
it("merges class names correctly", () => {
|
||||
expect(cn("a", "b")).toBe("a b");
|
||||
expect(cn("a", { b: true, c: false })).toBe("a b");
|
||||
});
|
||||
|
||||
it("handles tailwind class conflicts", () => {
|
||||
expect(cn("px-2 py-2", "px-4")).toBe("py-2 px-4");
|
||||
});
|
||||
});
|
||||
82
adminfront/tests/auth.spec.ts
Normal file
82
adminfront/tests/auth.spec.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Authentication', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Mock OIDC configuration
|
||||
await page.route('**/oidc/.well-known/openid-configuration', async route => {
|
||||
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",
|
||||
response_types_supported: ["code"],
|
||||
subject_types_supported: ["public"],
|
||||
id_token_signing_alg_values_supported: ["RS256"]
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('should redirect unauthorized users to login page', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
// Should be redirected to /login
|
||||
await expect(page).toHaveURL(/\/login/);
|
||||
await expect(page.locator('h1')).toContainText('Baron SSO');
|
||||
});
|
||||
|
||||
test('should allow access to dashboard when authenticated', async ({ page }) => {
|
||||
await page.addInitScript(() => {
|
||||
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,
|
||||
};
|
||||
window.localStorage.setItem(key, JSON.stringify(authData));
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
|
||||
// Wait for the auth loading to finish
|
||||
await expect(page.locator('.animate-spin')).not.toBeVisible();
|
||||
|
||||
// Should be on the dashboard/overview
|
||||
await expect(page.locator('aside')).toBeVisible();
|
||||
await expect(page.locator('h1')).toContainText('Admin Control');
|
||||
});
|
||||
|
||||
test('should logout and redirect to login page', async ({ page }) => {
|
||||
// Start authenticated
|
||||
await page.addInitScript(() => {
|
||||
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' },
|
||||
expires_at: Math.floor(Date.now() / 1000) + 3600,
|
||||
};
|
||||
window.localStorage.setItem(key, JSON.stringify(authData));
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
await expect(page.locator('aside')).toBeVisible();
|
||||
|
||||
// Mock window.confirm
|
||||
page.on('dialog', dialog => dialog.accept());
|
||||
|
||||
// Click logout button (label: ui.admin.nav.logout)
|
||||
await page.click('button:has-text("Logout"), button:has-text("로그아웃")');
|
||||
|
||||
await expect(page).toHaveURL(/\/login/);
|
||||
});
|
||||
});
|
||||
75
adminfront/tests/tenants.spec.ts
Normal file
75
adminfront/tests/tenants.spec.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Tenants Management', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Authenticate
|
||||
await page.addInitScript(() => {
|
||||
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,
|
||||
};
|
||||
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" } });
|
||||
});
|
||||
});
|
||||
|
||||
test('should list tenants', async ({ page }) => {
|
||||
await page.route('**/api/v1/admin/tenants*', async route => {
|
||||
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
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
await page.goto('/tenants');
|
||||
await expect(page.locator('h2')).toContainText('테넌트 목록');
|
||||
await expect(page.locator('table')).toContainText('Tenant A');
|
||||
});
|
||||
|
||||
test('should create a new tenant', async ({ page }) => {
|
||||
// Mock GET for list (empty) and for parents
|
||||
await page.route('**/api/v1/admin/tenants*', async route => {
|
||||
if (route.request().method() === 'GET') {
|
||||
await route.fulfill({ json: { items: [], total: 0, limit: 100, offset: 0 } });
|
||||
} else if (route.request().method() === 'POST') {
|
||||
await route.fulfill({
|
||||
json: { id: '2', name: 'New Tenant', slug: 'new-tenant', status: 'active', type: 'COMPANY' }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await page.goto('/tenants/new');
|
||||
|
||||
await page.fill('input >> nth=0', 'New Tenant');
|
||||
await page.fill('input >> nth=1', 'new-tenant');
|
||||
await page.fill('textarea', 'Description');
|
||||
|
||||
await page.click('button:has-text("생성")');
|
||||
|
||||
await expect(page).toHaveURL(/\/tenants$/);
|
||||
});
|
||||
|
||||
test('should show validation error on empty name', async ({ page }) => {
|
||||
await page.goto('/tenants/new');
|
||||
const submitBtn = page.locator('button:has-text("생성")');
|
||||
await expect(submitBtn).toBeDisabled();
|
||||
|
||||
await page.fill('input >> nth=0', 'Valid Name');
|
||||
await expect(submitBtn).not.toBeDisabled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user