-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(landing): added tests for landing page
- Loading branch information
1 parent
9c48e07
commit cc582ff
Showing
1 changed file
with
48 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |
cc582ff
There was a problem hiding this comment.
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