forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.test.tsx
More file actions
100 lines (85 loc) · 3.7 KB
/
Copy pathbutton.test.tsx
File metadata and controls
100 lines (85 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { screen, fireEvent } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { renderWithProviders } from "@/test/render";
import { Button, buttonVariants } from "./button";
describe("Button", () => {
it("renders with default variant", () => {
renderWithProviders(<Button>Click me</Button>);
const button = screen.getByRole("button", { name: /click me/i });
expect(button).toBeInTheDocument();
expect(button).toHaveClass("bg-primary");
});
it("renders with destructive variant", () => {
renderWithProviders(<Button variant="destructive">Delete</Button>);
const button = screen.getByRole("button", { name: /delete/i });
expect(button).toHaveClass("bg-destructive");
});
it("renders with outline variant", () => {
renderWithProviders(<Button variant="outline">Outline</Button>);
const button = screen.getByRole("button", { name: /outline/i });
expect(button).toHaveClass("border");
});
it("renders with secondary variant", () => {
renderWithProviders(<Button variant="secondary">Secondary</Button>);
const button = screen.getByRole("button", { name: /secondary/i });
expect(button).toHaveClass("bg-secondary");
});
it("renders with ghost variant", () => {
renderWithProviders(<Button variant="ghost">Ghost</Button>);
const button = screen.getByRole("button", { name: /ghost/i });
expect(button).toHaveClass("hover:bg-accent");
});
it("renders with link variant", () => {
renderWithProviders(<Button variant="link">Link</Button>);
const button = screen.getByRole("button", { name: /link/i });
expect(button).toHaveClass("underline-offset-4");
});
it("renders with small size", () => {
renderWithProviders(<Button size="sm">Small</Button>);
const button = screen.getByRole("button", { name: /small/i });
expect(button).toHaveClass("h-8");
});
it("renders with large size", () => {
renderWithProviders(<Button size="lg">Large</Button>);
const button = screen.getByRole("button", { name: /large/i });
expect(button).toHaveClass("h-10");
});
it("renders with icon size", () => {
renderWithProviders(<Button size="icon">Icon</Button>);
const button = screen.getByRole("button", { name: /icon/i });
expect(button).toHaveClass("h-9", "w-9");
});
it("calls onClick when clicked", () => {
const handleClick = vi.fn();
renderWithProviders(<Button onClick={handleClick}>Click</Button>);
fireEvent.click(screen.getByRole("button", { name: /click/i }));
expect(handleClick).toHaveBeenCalledTimes(1);
});
it("is disabled when disabled prop is true", () => {
renderWithProviders(<Button disabled>Disabled</Button>);
const button = screen.getByRole("button", { name: /disabled/i });
expect(button).toBeDisabled();
expect(button).toHaveClass("disabled:pointer-events-none");
});
it("forwards ref correctly", () => {
const ref = { current: null };
renderWithProviders(<Button ref={ref}>Ref</Button>);
expect(ref.current).toBeInstanceOf(HTMLButtonElement);
});
it("applies custom className", () => {
renderWithProviders(<Button className="custom-class">Custom</Button>);
const button = screen.getByRole("button", { name: /custom/i });
expect(button).toHaveClass("custom-class");
});
});
describe("buttonVariants", () => {
it("returns correct classes for default variant", () => {
const classes = buttonVariants({ variant: "default", size: "default" });
expect(classes).toContain("bg-primary");
expect(classes).toContain("h-9");
});
it("returns correct classes for destructive variant", () => {
const classes = buttonVariants({ variant: "destructive" });
expect(classes).toContain("bg-destructive");
});
});