Skip to content
This repository was archived by the owner on Feb 3, 2026. It is now read-only.

Commit 1662fe2

Browse files
committed
test: stabilize suites and registration CTA
1 parent ff3bae0 commit 1662fe2

30 files changed

+180
-1982
lines changed

__tests__/__mocks__/mockRegistry.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ import extendedMocks from "./extendedMocks";
1717
*/
1818
export const MockRegistrationLink = ({ className }: { className?: string }) => {
1919
return (
20-
<div data-testid="registration-link" className={className} role="link" aria-label="Registration Link">
21-
Registration Link
22-
</div>
20+
<a
21+
data-testid="registration-link"
22+
className={className}
23+
href="https://hackrpi2025.devpost.com/"
24+
target="_blank"
25+
rel="noopener noreferrer"
26+
>
27+
Register Here!
28+
</a>
2329
);
2430
};
2531

__tests__/components/about-us.test.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ jest.mock("next/navigation", () => ({
2525
jest.mock("@/components/themed-components/registration-link", () => {
2626
return {
2727
__esModule: true,
28-
default: ({ children, className }: { children?: React.ReactNode; className?: string }) => (
29-
<div data-testid="registration-link" className={className} role="link" aria-label="Registration Link">
30-
{children || "Registration Link"}
31-
</div>
28+
default: ({ className }: { className?: string }) => (
29+
<a
30+
data-testid="registration-link"
31+
href="https://hackrpi2025.devpost.com/"
32+
target="_blank"
33+
rel="noopener noreferrer"
34+
className={className}
35+
>
36+
Register Here!
37+
</a>
3238
),
3339
};
3440
});
@@ -110,19 +116,16 @@ describe("AboutUs Component", () => {
110116
});
111117

112118
it("renders the registration link with correct styling", () => {
113-
// 2025 best practice: Render the component and get the container
114119
const { container } = renderWithProviders(<AboutUs />);
115120

116-
// 2025 best practice: Use data-testid for more reliable selection
117-
const registrationLink = screen.getByTestId("registration-link");
121+
const registrationLink = screen.getByRole("link", { name: /register here!/i });
118122
expect(registrationLink).toBeInTheDocument();
119123
expect(registrationLink).toHaveClass("text-xl");
124+
expect(registrationLink).toHaveAttribute("href", "https://hackrpi2025.devpost.com/");
120125

121-
// 2025 best practice: Find the REGISTER NOW text using a pattern
122126
const registerNowText = screen.getByText(/REGISTER NOW!/i);
123127
expect(registerNowText).toBeInTheDocument();
124128

125-
// Verify they are both in the document but don't assert they're in the same container
126129
expect(container).toContainElement(registrationLink);
127130
expect(container).toContainElement(registerNowText);
128131
});
@@ -137,7 +140,7 @@ describe("AboutUs Component", () => {
137140

138141
// Check styling directly on the element with data-testid
139142
expect(registerBanner).toHaveClass("bg-hackrpi-secondary-orange");
140-
expect(registerBanner).toHaveClass("text-black");
143+
expect(registerBanner).toHaveClass("text-white");
141144
expect(registerBanner).toHaveClass("overflow-hidden");
142145
expect(registerBanner).toHaveClass("whitespace-nowrap");
143146
});
@@ -187,7 +190,7 @@ describe("AboutUs Component", () => {
187190

188191
// Check that key elements are still visible on mobile
189192
expect(screen.getByRole("heading", { name: /About HackRPI/i })).toBeInTheDocument();
190-
expect(screen.getByTestId("registration-link")).toBeInTheDocument();
193+
expect(screen.getByRole("link", { name: /register here!/i })).toBeInTheDocument();
191194

192195
// Clean up mobile test and set up desktop test
193196
cleanup();
@@ -197,7 +200,7 @@ describe("AboutUs Component", () => {
197200

198201
// Verify desktop layout elements
199202
expect(screen.getByRole("heading", { name: /About HackRPI/i })).toBeInTheDocument();
200-
expect(screen.getByTestId("registration-link")).toBeInTheDocument();
203+
expect(screen.getByRole("link", { name: /register here!/i })).toBeInTheDocument();
201204
});
202205

203206
// 2025 Best Practice: Add automated accessibility testing

__tests__/components/event.test.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jest.mock("next/image", () => ({
6161
}));
6262

6363
// Import the component after all mocks are defined
64-
import EventPage from "@/app/event/page";
64+
import EventPage from "@/app/(with-layout)/event/page";
6565

6666
describe("Event Page", () => {
6767
beforeEach(() => {
@@ -71,11 +71,9 @@ describe("Event Page", () => {
7171
it("renders the main layout components", () => {
7272
render(<EventPage />);
7373

74-
// Check if the navbar component is rendered
75-
expect(screen.getByTestId("nav-bar")).toBeInTheDocument();
76-
77-
// Note: Footer is imported but not actually used in the component
78-
// so we should not expect it in the test
74+
// Verify key structural headings render
75+
expect(screen.getByText("Location:")).toBeInTheDocument();
76+
expect(screen.getByText("Need Help?")).toBeInTheDocument();
7977
});
8078

8179
it("renders the map component", () => {

__tests__/components/faq.test.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ import "@testing-library/jest-dom";
88
jest.mock("@/components/themed-components/registration-link", () => {
99
return {
1010
__esModule: true,
11-
default: ({ children, className }: { children?: React.ReactNode; className?: string }) => (
12-
<div data-testid="registration-link" className={className} role="link" aria-label="Registration Link">
13-
{children || "Registration Link"}
14-
</div>
11+
default: ({ className }: { className?: string }) => (
12+
<a
13+
data-testid="registration-link"
14+
href="https://hackrpi2025.devpost.com/"
15+
target="_blank"
16+
rel="noopener noreferrer"
17+
className={className}
18+
>
19+
Register Here!
20+
</a>
1521
),
1622
};
1723
});
@@ -95,8 +101,9 @@ describe("FAQ Component", () => {
95101
fireEvent.click(registrationFAQ);
96102

97103
// Check if the registration link is rendered
98-
const registrationLink = screen.getByTestId("registration-link");
104+
const registrationLink = screen.getByRole("link", { name: /register here!/i });
99105
expect(registrationLink).toBeInTheDocument();
106+
expect(registrationLink).toHaveAttribute("href", "https://hackrpi2025.devpost.com/");
100107
});
101108

102109
it("renders the contact information at the bottom", () => {

__tests__/components/footer.test.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jest.mock("next/image", () => ({
1111
}));
1212

1313
// Mock logo import
14-
jest.mock("@/public/HackRPI_Logo_Yellow_Arrow.png", () => ({
15-
default: "mock-logo-path",
14+
jest.mock("@/public/Retro_HackRPI_Logo.png", () => ({
15+
default: "mock-retro-logo",
1616
}));
1717

1818
jest.mock("@/components/socials-links/social-links", () => {
@@ -24,9 +24,15 @@ jest.mock("@/components/socials-links/social-links", () => {
2424
jest.mock("@/components/themed-components/registration-link", () => {
2525
return function MockRegistrationLink({ className }: { className?: string }) {
2626
return (
27-
<div data-testid="registration-link" className={className}>
28-
Registration Link
29-
</div>
27+
<a
28+
data-testid="registration-link"
29+
className={className}
30+
href="https://hackrpi2025.devpost.com/"
31+
target="_blank"
32+
rel="noopener noreferrer"
33+
>
34+
Register Here!
35+
</a>
3036
);
3137
};
3238
});
@@ -72,6 +78,7 @@ describe("Footer Component", () => {
7278
expect(registrationLink).toBeInTheDocument();
7379
expect(registrationLink).toHaveClass("text-xl");
7480
expect(registrationLink).toHaveClass("mb-4");
81+
expect(registrationLink).toHaveAttribute("href", "https://hackrpi2025.devpost.com/");
7582
});
7683

7784
it("renders the social links", () => {

__tests__/components/last-year.test.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ jest.mock("@/components/themed-components/hackrpi-link", () => {
8080
};
8181
});
8282

83+
jest.mock("@/components/prev-projects/LastYearCollage", () => {
84+
return function MockLastYearCollage() {
85+
return (
86+
<div data-testid="photo-gallery">
87+
{Array.from({ length: 12 }).map((_, index) => (
88+
<img
89+
key={index}
90+
data-testid="mock-image"
91+
src={`/lastYearPhotos/photo-${index + 1}.jpg`}
92+
alt={`HackRPI XI Photo ${index + 1}`}
93+
/>
94+
))}
95+
</div>
96+
);
97+
};
98+
});
99+
83100
jest.mock("next/image", () => ({
84101
__esModule: true,
85102
default: (props: any) => {
@@ -88,7 +105,7 @@ jest.mock("next/image", () => ({
88105
}));
89106

90107
// Import the component after all mocks are defined
91-
import PastYearProjects from "@/app/last-year/page";
108+
import PastYearProjects from "@/app/(with-layout)/last-year/page";
92109

93110
describe("Last Year Projects Page", () => {
94111
beforeEach(() => {

__tests__/components/nav-bar.test.tsx

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import { render, screen, cleanup } from "@testing-library/react";
3-
import NavBar from "@/components/nav-bar/nav-bar";
3+
import NavBar, { links as navLinks } from "@/components/nav-bar/nav-bar";
44
import { renderWithProviders, resetAllMocks, setWindowDimensions } from "../test-utils";
55

66
/**
@@ -42,29 +42,6 @@ jest.mock("@/data/nav-bar-links", () => {
4242
};
4343
});
4444

45-
// Mock the links directly in the NavBar component
46-
jest.mock("@/components/nav-bar/nav-bar", () => {
47-
const originalModule = jest.requireActual("@/components/nav-bar/nav-bar");
48-
return {
49-
__esModule: true,
50-
...originalModule,
51-
links: [
52-
{
53-
name: "Home",
54-
links: [
55-
{ href: "/", children: "Home" },
56-
{ href: "/#about", children: "About" },
57-
],
58-
},
59-
{
60-
name: "HackRPI XI",
61-
links: [{ href: "/last-year#winners", children: "Winners" }],
62-
},
63-
],
64-
default: originalModule.default,
65-
};
66-
});
67-
6845
// Mock MLH Banner
6946
jest.mock("@/components/mlh-banner/mlh-banner", () => {
7047
return function MockMlhBanner() {
@@ -134,9 +111,10 @@ describe("NavBar Component", () => {
134111
// Act - Render the component
135112
renderWithProviders(<NavBar showOnScroll={true} />);
136113

137-
// Assert - Check if links are passed correctly - we expect 2 links based on our mock
114+
// Assert - Check if links are passed correctly based on the exported navigation data
138115
const mobileNav = screen.getByTestId("nav-bar-mobile");
139-
expect(mobileNav.textContent).toContain("2 links");
116+
const expectedCount = navLinks.length;
117+
expect(mobileNav.textContent).toContain(`${expectedCount} links`);
140118

141119
// Clean up before rendering again
142120
cleanup();
@@ -146,7 +124,7 @@ describe("NavBar Component", () => {
146124
renderWithProviders(<NavBar showOnScroll={true} />);
147125

148126
const desktopNav = screen.getByTestId("nav-bar-desktop");
149-
expect(desktopNav.textContent).toContain("2 links");
127+
expect(desktopNav.textContent).toContain(`${expectedCount} links`);
150128
});
151129

152130
it("should handle showOnScroll prop correctly", async () => {

__tests__/components/nav-bar/desktop/nav-bar-desktop.test.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { render, screen } from "@testing-library/react";
22
import "@testing-library/jest-dom";
33

44
// Mock the image imports
5-
jest.mock("@/public/HackRPI_Logo_Yellow_Arrow.png", () => "logo-image-stub");
5+
jest.mock("@/public/Retro_HackRPI_Logo.png", () => "logo-image-stub");
66
jest.mock("next/image", () => ({
77
__esModule: true,
88
default: (props: any) => {
@@ -12,11 +12,6 @@ jest.mock("next/image", () => ({
1212
}));
1313

1414
// Mock the registration button
15-
jest.mock("@/components/themed-components/registration-link", () => ({
16-
__esModule: true,
17-
default: () => <div data-testid="registration-button">Register Now</div>,
18-
}));
19-
2015
// Mock NavGroupComponent
2116
jest.mock("@/components/nav-bar/desktop/nav-group", () => ({
2217
__esModule: true,
@@ -70,19 +65,14 @@ describe("DesktopNavBar Component", () => {
7065

7166
// Check direct links
7267
expect(screen.getByText("Sponsor Us")).toBeInTheDocument();
73-
expect(screen.getByText("Event Info")).toBeInTheDocument();
74-
expect(screen.getByText("Schedule")).toBeInTheDocument();
75-
expect(screen.getByText("Announcements")).toBeInTheDocument();
76-
expect(screen.getByText("Prizes")).toBeInTheDocument();
77-
expect(screen.getByText("2048 Leaderboard")).toBeInTheDocument();
7868
expect(screen.getByText("Code of Conduct")).toBeInTheDocument();
7969
});
8070

81-
it("includes registration button", () => {
71+
it("includes registration link", () => {
8272
render(<DesktopNavBar links={mockLinks} />);
8373

84-
// Check for the registration button
85-
expect(screen.getByTestId("registration-button")).toBeInTheDocument();
74+
const registerLink = screen.getByRole("link", { name: /register/i });
75+
expect(registerLink).toHaveAttribute("href", "https://hackrpi2025.devpost.com/");
8676
});
8777

8878
it("applies correct styling to the navbar", () => {

__tests__/components/resources.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jest.mock("next/image", () => ({
4646
}));
4747

4848
// Import the component after all mocks are defined
49-
import ResourcesPage from "@/app/resources/page";
49+
import ResourcesPage from "@/app/(with-layout)/resources/page";
5050

5151
describe("Resources Page", () => {
5252
beforeEach(() => {
@@ -56,9 +56,9 @@ describe("Resources Page", () => {
5656
it("renders the main layout components", () => {
5757
render(<ResourcesPage />);
5858

59-
// Check if the main structural components are rendered
60-
expect(screen.getByTestId("nav-bar")).toBeInTheDocument();
61-
// Footer is imported but not actually used in the component
59+
// Verify primary headings render
60+
expect(screen.getByText("Web Development")).toBeInTheDocument();
61+
expect(screen.getByText("Submitting Your Project")).toBeInTheDocument();
6262
});
6363

6464
it("renders all resource section headings", () => {

__tests__/integration/navigation.test.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
*/
44
import React from "react";
55
import { screen, within, act } from "@testing-library/react";
6-
import Home from "@/app/page";
6+
import Home from "@/app/(without-layout)/page";
77
import {
88
renderWithProviders,
99
resetAllMocks,
1010
mockHomePageElements,
1111
mockScrollIntoView,
1212
checkNavigationAccessibility,
1313
} from "../test-utils";
14-
import { MockIntersectionObserver, MockFooter } from "../__mocks__/mockRegistry";
14+
import { MockIntersectionObserver } from "../__mocks__/mockRegistry";
1515
import "@testing-library/jest-dom";
1616
import { fireEvent } from "@testing-library/react";
1717

@@ -25,6 +25,14 @@ function MockTitle({ children }: { children: React.ReactNode }) {
2525
);
2626
}
2727

28+
function MockFooterComponent() {
29+
return (
30+
<div data-testid="mock-footer" role="contentinfo">
31+
Footer Component
32+
</div>
33+
);
34+
}
35+
2836
// 2025 Best Practice: More organized setup with clear purpose
2937
const mockHandleFAQClick = jest.fn();
3038
const mockHandleAboutClick = jest.fn();
@@ -125,7 +133,7 @@ jest.mock("@/components/sponsors", () => {
125133
// Use centralized mock registry for Footer
126134
jest.mock("@/components/footer/footer", () => ({
127135
__esModule: true,
128-
default: MockFooter,
136+
default: MockFooterComponent,
129137
}));
130138

131139
jest.mock("@/components/faq/faq", () => {

0 commit comments

Comments
 (0)