|
1 | 1 | import "@testing-library/jest-dom/extend-expect"
|
2 |
| -import { render } from "@testing-library/react" |
3 |
| -import React from "react" |
4 | 2 |
|
| 3 | +import React from "react" |
| 4 | +import { render, screen } from "@testing-library/react" |
5 | 5 | import { Card } from "./Card"
|
6 | 6 |
|
7 |
| -describe("Card component", () => { |
8 |
| - test("renders properly", () => { |
9 |
| - const { getByTestId } = render(<Card />) |
10 |
| - expect(getByTestId("card")).toBeInTheDocument() |
| 7 | +describe("Card", () => { |
| 8 | + // ... existing imports and setup ... |
| 9 | + |
| 10 | + it("renders children correctly", () => { |
| 11 | + render(<Card>Test Content</Card>) |
| 12 | + expect(screen.getByText("Test Content")).toBeInTheDocument() |
11 | 13 | })
|
12 | 14 |
|
13 |
| - test("should render a card with all props", () => { |
14 |
| - const { getByTestId } = render( |
15 |
| - <Card |
16 |
| - variant="card" |
17 |
| - title="Title" |
18 |
| - subtitle="Subtitle" |
19 |
| - cover="cover.jpg" |
20 |
| - tags={[<div key="tag">Tag</div>]} |
21 |
| - users={<div>Users</div>} |
22 |
| - orientation="vertical" |
23 |
| - actions={[<button key="action">Action</button>]} |
24 |
| - stats={[{ icon: <div key="icon">Icon</div>, number: 5 }]} |
25 |
| - /> |
| 15 | + it("applies custom width and height", () => { |
| 16 | + render( |
| 17 | + <Card width={200} height={100}> |
| 18 | + Test Content |
| 19 | + </Card> |
26 | 20 | )
|
27 |
| - expect(getByTestId("card")).toBeInTheDocument() |
| 21 | + const cardContainer = screen.getByText("Test Content").closest("div") |
| 22 | + expect(cardContainer).toHaveStyle({ width: "200px", height: "100px" }) |
| 23 | + }) |
| 24 | + |
| 25 | + it("applies default width and height when not provided", () => { |
| 26 | + render(<Card>Test Content</Card>) |
| 27 | + const cardContainer = screen.getByText("Test Content").closest("div") |
| 28 | + expect(cardContainer).toHaveStyle({ width: "40vw", height: "inherit" }) |
| 29 | + }) |
| 30 | + |
| 31 | + it("applies alignment class correctly", () => { |
| 32 | + render(<Card align="center">Test Content</Card>) |
| 33 | + const cardContainer = screen.getByText("Test Content").closest("div") |
| 34 | + expect(cardContainer).toHaveClass("items-center") |
| 35 | + }) |
| 36 | + |
| 37 | + it("applies custom className", () => { |
| 38 | + render(<Card className="custom-class">Test Content</Card>) |
| 39 | + const cardContainer = screen.getByText("Test Content").closest("div") |
| 40 | + expect(cardContainer).toHaveClass("custom-class") |
28 | 41 | })
|
29 | 42 | })
|
0 commit comments