Skip to content

Commit

Permalink
Merge pull request #336 from ReDI-School/add-ProductHighlights-tests
Browse files Browse the repository at this point in the history
Add tests for ProductHighlight Component
  • Loading branch information
dvnishshanka authored Dec 6, 2024
2 parents fb7a440 + d2afcc0 commit efadead
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/components/ProductHighlight/ProductHighlight.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { render, screen } from "@testing-library/react";
import ProductHighlight from "./ProductHighlight";
import { CHECK_IN, AWARD, CANCELLATION } from "../../constants/constants";
import { describe, it, expect } from "vitest";

describe("ProductHighlight Component", () => {
const mockHighlights = [
{ type: CHECK_IN, text: "Easy Check-In", subText: "Arrive anytime after 3 PM" },
{ type: AWARD, text: "Award-Winning Stay", subText: "Winner of 2023 Travelers' Choice" },
{ type: CANCELLATION, text: "Flexible Cancellation", subText: "Get a full refund if you change your mind." },
{ type: "OTHER", text: "Free Wifi", subText: "Superhosts are experienced, highly rated Hosts." },
];

it("renders all highlights correctly", () => {
render(<ProductHighlight highlights={mockHighlights} />);

// Assert that all text content appears
mockHighlights.forEach((highlight) => {
expect(screen.getByText(highlight.text)).toBeInTheDocument();

Check failure on line 19 in src/components/ProductHighlight/ProductHighlight.test.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

src/components/ProductHighlight/ProductHighlight.test.jsx > ProductHighlight Component > renders all highlights correctly

Error: Invalid Chai property: toBeInTheDocument ❯ src/components/ProductHighlight/ProductHighlight.test.jsx:19:46 ❯ src/components/ProductHighlight/ProductHighlight.test.jsx:18:20
expect(screen.getByText(highlight.subText)).toBeInTheDocument();
});

// Check the icons are rendered (using the `presentation` role for SVGs)
const icons = screen.getAllByRole("presentation", { hidden: true });
expect(icons).toHaveLength(mockHighlights.length);
});
it("renders no highlights when the list is empty", () => {
render(<ProductHighlight highlights={[]} />);

const listItems = screen.queryAllByRole("listitem");
expect(listItems).toHaveLength(0); // No highlights should be rendered
});

});

0 comments on commit efadead

Please sign in to comment.