Skip to content

Commit

Permalink
test: test file for Section.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
maxitect committed Dec 13, 2024
1 parent 02e8ab7 commit f345f93
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions __tests__/Section.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Section from "@/app/needs/components/Section";
import { render, screen, fireEvent } from "@testing-library/react";

describe("Section Component", () => {
const mockHandleOpen = jest.fn();
const mockCategoryData = {
key: "Category 1",
items: [
{
id: "1",
name: "Need 1",
highlighted: true,
label: "Need 1",
mood: "joy",
},
{
id: "2",
name: "Need 2",
highlighted: false,
label: "Need 2",
mood: "",
},
],
};

test("renders section with items", () => {
render(
<Section categoryData={mockCategoryData} handleOpen={mockHandleOpen} />
);

expect(screen.getByText("Category 1")).toBeInTheDocument();
expect(screen.getByText("Need 1")).toBeInTheDocument();
expect(screen.getByText("Need 2")).toBeInTheDocument();
});

test("applies correct styles for highlighted and non-highlighted items", () => {
render(
<Section categoryData={mockCategoryData} handleOpen={mockHandleOpen} />
);

const highlightedButton = screen.getByText("Need 1");
const nonHighlightedButton = screen.getByText("Need 2");

expect(highlightedButton).toHaveClass("bg-twd-mood-joy-yellow");
expect(nonHighlightedButton).toHaveClass("bg-gray-600");
});

test("calls handleOpen when item is clicked", () => {
render(
<Section categoryData={mockCategoryData} handleOpen={mockHandleOpen} />
);

fireEvent.click(screen.getByText("Need 1"));
expect(mockHandleOpen).toHaveBeenCalledWith(mockCategoryData.items[0]);
});
});

0 comments on commit f345f93

Please sign in to comment.