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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user