|
1 |
| - |
2 | 1 | import "@testing-library/jest-dom/extend-expect"
|
3 | 2 | import { render } from "@testing-library/react"
|
4 | 3 | import React from "react"
|
5 | 4 |
|
6 |
| -import { Accordion } from "./Accordion" |
| 5 | +import { IconChevronDown } from "@tabler/icons-react" |
| 6 | +import { Accordion } from "." |
7 | 7 |
|
8 | 8 | describe("Accordion component", () => {
|
9 |
| - test("renders properly", () => {}) |
| 9 | + it("should render the accordion container with the correct styles and classes", () => { |
| 10 | + // Arrange |
| 11 | + const data = [ |
| 12 | + { label: "Item 1", children: "Content 1" }, |
| 13 | + { label: "Item 2", children: "Content 2" }, |
| 14 | + ] |
| 15 | + const collapseIcon = <IconChevronDown /> |
| 16 | + const color = "warm" |
| 17 | + const size = "md" |
| 18 | + const multiActive = false |
| 19 | + |
| 20 | + // Act |
| 21 | + const { getByTestId } = render( |
| 22 | + <Accordion |
| 23 | + data={data} |
| 24 | + collapseIcon={collapseIcon} |
| 25 | + color={color} |
| 26 | + size={size} |
| 27 | + multiActive={multiActive} |
| 28 | + /> |
| 29 | + ) |
| 30 | + |
| 31 | + // Assert |
| 32 | + const container = getByTestId("accordion-container") |
| 33 | + expect(container).toBeInTheDocument() |
| 34 | + expect(container).toHaveClass("mx-auto", "flex", "flex-col", "gap-2") |
| 35 | + expect(container).toHaveClass("w-[600px]") |
| 36 | + }) |
| 37 | + |
| 38 | + it("should render each item in the data array with the correct styles and classes", () => { |
| 39 | + const data = [ |
| 40 | + { label: "Item 1", children: "Content 1" }, |
| 41 | + { label: "Item 2", children: "Content 2" }, |
| 42 | + ] |
| 43 | + const collapseIcon = <IconChevronDown /> |
| 44 | + const color = "warm" |
| 45 | + const size = "md" |
| 46 | + const multiActive = false |
| 47 | + |
| 48 | + const { getAllByTestId } = render( |
| 49 | + <Accordion |
| 50 | + data={data} |
| 51 | + collapseIcon={collapseIcon} |
| 52 | + color={color} |
| 53 | + size={size} |
| 54 | + multiActive={multiActive} |
| 55 | + /> |
| 56 | + ) |
| 57 | + |
| 58 | + const itemHeaders = getAllByTestId("accordion-item-header") |
| 59 | + expect(itemHeaders).toHaveLength(2) |
| 60 | + expect(itemHeaders[0]).toHaveClass( |
| 61 | + "p-3", |
| 62 | + "flex", |
| 63 | + "items-center", |
| 64 | + "justify-between" |
| 65 | + ) |
| 66 | + expect(itemHeaders[1]).toHaveClass( |
| 67 | + "p-3", |
| 68 | + "flex", |
| 69 | + "items-center", |
| 70 | + "justify-between" |
| 71 | + ) |
| 72 | + }) |
| 73 | + |
| 74 | + it("should handle an empty data array", () => { |
| 75 | + const data: any[] = [] |
| 76 | + const collapseIcon = <IconChevronDown /> |
| 77 | + const color = "warm" |
| 78 | + const size = "md" |
| 79 | + const multiActive = false |
| 80 | + |
| 81 | + const { queryByTestId } = render( |
| 82 | + <Accordion |
| 83 | + data={data} |
| 84 | + collapseIcon={collapseIcon} |
| 85 | + color={color} |
| 86 | + size={size} |
| 87 | + multiActive={multiActive} |
| 88 | + /> |
| 89 | + ) |
| 90 | + |
| 91 | + expect(queryByTestId("accordion-item-header")).not.toBeInTheDocument() |
| 92 | + }) |
10 | 93 | })
|
0 commit comments