Skip to content

Commit a54cc6b

Browse files
committed
feat: improve community header test
1 parent 9a7c496 commit a54cc6b

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

__tests__/components/sections/communities/_partials/Header.test.tsx

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,44 @@ import Header from "@/components/sections/communities/_partials/Header";
22
import { render, screen } from "@testing-library/react";
33
import "@testing-library/jest-dom";
44

5+
const headerProps = {
6+
description: "Test Description",
7+
title: "Test Title",
8+
subtitle: "Test Subtitle",
9+
isTeamChallenge: true,
10+
isHackathon: true,
11+
};
12+
513
describe("Header", () => {
614
it("renders the Header with Props", () => {
7-
render(<Header description="Test Description" title="Test Title" subtitle="Test Subtitle" isTeamChallenge={true} isHackathon={true} />);
8-
expect(screen.getByText("Test Description")).toBeInTheDocument();
9-
expect(screen.getByText("Test Title")).toBeInTheDocument();
10-
expect(screen.getByText("Test Subtitle")).toBeInTheDocument();
11-
expect(screen.getByText("Hackathon")).toBeInTheDocument();
15+
render(
16+
<Header
17+
description={headerProps.description}
18+
title={headerProps.title}
19+
subtitle={headerProps.subtitle}
20+
isTeamChallenge={headerProps.isTeamChallenge}
21+
isHackathon={headerProps.isHackathon}
22+
/>
23+
);
24+
expect(screen.getByRole("heading", { name: headerProps.title })).toBeInTheDocument();
25+
expect(screen.getByRole("heading", { name: new RegExp(headerProps.subtitle) })).toBeInTheDocument();
26+
expect(screen.getByTestId("tag")).toBeInTheDocument();
27+
expect(screen.getByText(headerProps.description)).toBeInTheDocument();
1228
});
1329

1430
it("does not render subtitle when not provided", () => {
1531
render(<Header />);
16-
expect(screen.queryByText("Test Subtitle")).not.toBeInTheDocument();
17-
});
18-
19-
it("conditionally renders the description", () => {
20-
render(<Header description="Test Description" />);
21-
expect(screen.getByText("Test Description")).toBeInTheDocument();
32+
expect(screen.queryByRole("heading", { name: new RegExp(headerProps.subtitle) })).toBe(null);
33+
expect(screen.queryByRole("tag")).toBe(null);
2234
});
2335

24-
it("renders 'TEAM' tag when isTeamChallenge is true and isHackathon is false", () => {
25-
render(<Header subtitle="Test Subtitle" isTeamChallenge={true} isHackathon={false} />);
36+
it("renders 'TEAM' if isHackathon is false", () => {
37+
render(<Header subtitle={headerProps.subtitle} isTeamChallenge={headerProps.isTeamChallenge} />);
2638
expect(screen.getByText("TEAM")).toBeInTheDocument();
2739
});
2840

29-
it("does not render 'TEAM' or 'Hackathon' tag when isTeamChallenge is false", () => {
30-
render(<Header />);
31-
expect(screen.queryByText("TEAM")).not.toBeInTheDocument();
32-
expect(screen.queryByText("Hackathon")).not.toBeInTheDocument();
41+
it("renders 'Hackathon' if isHackathon is true", () => {
42+
render(<Header subtitle={headerProps.subtitle} isTeamChallenge={headerProps.isTeamChallenge} isHackathon={headerProps.isHackathon} />);
43+
expect(screen.getByText("Hackathon")).toBeInTheDocument();
3344
});
3445
});

0 commit comments

Comments
 (0)