Skip to content

Commit

Permalink
test(landing): added tests for landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
nishchay17 committed Nov 19, 2023
1 parent 9c48e07 commit cc582ff
Showing 1 changed file with 48 additions and 13 deletions.
61 changes: 48 additions & 13 deletions __test__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,58 @@
import { render, screen } from "@testing-library/react";
import { fireEvent, render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import mockRouter from "next-router-mock";
import { MemoryRouterProvider } from "next-router-mock/MemoryRouterProvider";

import Home from "../app/page";
import Hero from "../components/Landing/HeroSection";
import Projects from "../components/Landing/Projects";
import Tech from "../components/Landing/Tech";
import { projects } from "../config/project";
import TECH from "../config/tech";

describe("Home Page tests", () => {
it("renders the heading", () => {
const intersectionObserverMock = () => ({
observe: () => null,
unobserve: () => null,
disconnect: () => null,
});
window.IntersectionObserver = jest
.fn()
.mockImplementation(intersectionObserverMock);
jest.mock("next/router", () => jest.requireActual("next-router-mock"));

render(<Home />);
beforeAll(() => {
const intersectionObserverMock = () => ({
observe: () => null,
unobserve: () => null,
disconnect: () => null,
});
window.IntersectionObserver = jest
.fn()
.mockImplementation(intersectionObserverMock);
});

describe("Home Page tests", () => {
it("renders the hero heading", () => {
render(<Hero />);
const heading = screen.getByRole("heading", {
name: /Hello there I am Nishchay/i,
});
expect(heading).toBeInTheDocument();
});
it("renders all the projects", () => {
render(<Projects projects={[...projects]} />);
projects.forEach((project) => {
const heading = screen.getByText(project.name);
expect(heading).toBeInTheDocument();
});
});
it("redirects to project page on chick", () => {
mockRouter.push("/");
render(<Projects projects={[{ ...projects[0] }]} />, {
wrapper: MemoryRouterProvider,
});
const link = screen.getByRole("link");

expect(link).toBeInTheDocument();
fireEvent.click(link);
expect(mockRouter.asPath).toEqual(`/project/${projects[0].id}`);
});
it("renders all the technologies", () => {
render(<Tech techs={[...TECH]} />);
TECH.forEach((tech) => {
const techText = screen.getByText(tech);
expect(techText).toBeInTheDocument();
});
});
});

1 comment on commit cc582ff

@vercel
Copy link

@vercel vercel bot commented on cc582ff Nov 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

portfolio – ./

portfolio-nishchay17.vercel.app
nishchay17.vercel.app
portfolio-git-main-nishchay17.vercel.app

Please sign in to comment.