diff --git a/web/src/Components/Navbar.tsx b/web/src/Components/Navbar.tsx index 759eba0..613cde9 100644 --- a/web/src/Components/Navbar.tsx +++ b/web/src/Components/Navbar.tsx @@ -35,7 +35,7 @@ export default function Navbar() {
- UADS Logo + UADS Logo {/* Navlinks */}
@@ -53,7 +53,7 @@ export default function Navbar() { {/* Hamburger button */}
-
@@ -63,7 +63,7 @@ export default function Navbar() { {/* Mobile Menu */} {open && (
- diff --git a/web/src/components/__tests__/Navbar.test.tsx b/web/src/components/__tests__/Navbar.test.tsx new file mode 100644 index 0000000..97d1360 --- /dev/null +++ b/web/src/components/__tests__/Navbar.test.tsx @@ -0,0 +1,63 @@ +import { render, screen, fireEvent } from "@testing-library/react"; +import { MemoryRouter } from "react-router-dom"; +import Navbar from "../Navbar"; +import "@testing-library/jest-dom"; + +describe("Navbar Component", () => { + it("Should render the logo", () => { + render( + + + + ); + + const logo = screen.getByAltText(/UADS Logo/i); + expect(logo).toBeInTheDocument(); + expect(logo).toHaveAttribute("src", "/src/assets/uads_logo.svg"); + }); + + it("Should render all navigation links", () => { + render( + + + + ); + + const links = [ + { title: "Home", href: "/" }, + { title: "About", href: "/about" }, + { title: "Events", href: "/events" }, + { title: "Sponsors", href: "/sponsors" }, + { title: "Join", href: "/signup" }, + ]; + + links.forEach((link) => { + const navLink = screen.getByText(new RegExp(link.title, "i")); + expect(navLink).toBeInTheDocument(); + expect(navLink).toHaveAttribute("href", link.href); + }); + }); + + it("Should render hamburger button in mobile view and display close button", () => { + render( + + + + ); + + // Set viewport size to simulate mobile view + window.innerWidth = 500; + window.dispatchEvent(new Event("resize")); + + // Check if hamburger button is visible in mobile view + const hamburgerButtonMobile = screen.getByRole("button", { name: /openMenu/i }); + expect(hamburgerButtonMobile).toBeVisible(); + + // Click the hamburger button to open the mobile menu + fireEvent.click(hamburgerButtonMobile); + + // Check if close menu button is visible after clicking the hamburger button + const closeButtonMobile = screen.getByRole("button", { name: /closeMenu/i }); + expect(closeButtonMobile).toBeVisible(); + }); +});