Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests/navbar #43

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions __tests__/components/common/navbar/Navbar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from "react";
import { fireEvent, render, screen } from "@testing-library/react";

import { NavbarLink } from "@/components/common/Navbar/Navbar.types";
import { NAVBAR_LINKS } from "@/components/common/Navbar/Navbar.constants";

import Navbar from "@/components/common/Navbar/Navbar";

describe("Navbar Component", () => {
it("should render the Navbar", () => {
render(<Navbar />);

const nav = screen.getByRole("banner");

expect(nav).toBeInTheDocument();

// nav links assertions - desktop
NAVBAR_LINKS.forEach((link: NavbarLink) => {
const navLink = screen.getAllByText(link.name)[0];
expect(navLink).toHaveTextContent(link.name);
});

// signin button assertions
const signinButton = screen.getByTestId("signin-button");
const signInText = screen.getByText("Sign in with Github");

expect(signInText).toBeInTheDocument();
expect(signinButton).toBeInTheDocument();
expect(signinButton).toHaveAttribute("href", "login url will come here");
});

it("should render the mobile navbar when hamburger button is clicked", () => {
render(<Navbar />);

const mobileNav = screen.queryByTestId("mobile-nav");
const hamburgerButton = screen.queryByRole("button");

// hamburgerButton assertions
expect(hamburgerButton).toBeInTheDocument();
expect(hamburgerButton).toHaveClass("hamburger");

// toggle navlinks assertions
expect(mobileNav).toHaveClass("hidden");

fireEvent.click(hamburgerButton!);

expect(mobileNav).toHaveClass("visible");

// nav links assertions - mobile
NAVBAR_LINKS.forEach((link: NavbarLink) => {
const navLink = screen.queryAllByText(link.name)[1];
expect(navLink).toHaveTextContent(link.name);
});
});
});
24 changes: 24 additions & 0 deletions src/components/common/Navbar/Navbar.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NavbarLink } from "./Navbar.types";

export const NAVBAR_LINKS: NavbarLink[] = [
{
id: "welcome-site",
name: "Welcome",
link: process.env.NEXT_PUBLIC_WELCOME_SITE,
},
{
id: "events-site",
name: "Events",
link: `${process.env.NEXT_PUBLIC_WWW_SITE}/events`,
},
{
id: "members-site",
name: "Members",
link: process.env.NEXT_PUBLIC_MEMBERS_SITE,
},
{
id: "status-site",
name: "Status",
link: process.env.NEXT_PUBLIC_STATUS_SITE,
},
];
5 changes: 5 additions & 0 deletions src/components/common/Navbar/Navbar.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type NavbarLink = {
id: string;
name: string;
link: string;
};