Skip to content

Commit

Permalink
Update Project component by passing mock params in test
Browse files Browse the repository at this point in the history
  • Loading branch information
saisab29 committed Dec 9, 2024
1 parent 0e5afdd commit 84fbcdf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions __tests__/Project.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* eslint-disable testing-library/no-node-access */
/* eslint-disable jsx-a11y/alt-text */
/* eslint-disable @next/next/no-img-element */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { render, screen, fireEvent } from "@testing-library/react";
import Project from "@/app/projects/[id]/page";
import { useParams } from "next/navigation";
Expand Down Expand Up @@ -39,7 +43,8 @@ describe("Project Page", () => {
});

it("renders the correct project based on the id from the URL", () => {
render(<Project />);
const mockParams = Promise.resolve({ id: "1" });
render(<Project params={mockParams} />);

const projectName = screen.getByText("Project 1");
const projectDescription = screen.getByText("Description 1");
Expand All @@ -51,7 +56,8 @@ describe("Project Page", () => {
});

it("renders the similar projects section with the correct current project id", () => {
render(<Project />);
const mockParams = Promise.resolve({ id: "1" });
render(<Project params={mockParams} />);

// Test that the SimilarProjects component is rendered
const similarProject = screen.getByText("You may also like");
Expand All @@ -63,7 +69,8 @@ describe("Project Page", () => {
});

it("renders the Visit button and links correctly", () => {
render(<Project />);
const mockParams = Promise.resolve({ id: "1" });
render(<Project params={mockParams} />);

// Target the Visit button for the screen size you're testing
const visitButton = screen.getAllByRole("button", { name: /visit/i });
Expand All @@ -82,7 +89,8 @@ describe("Project Page", () => {
});

it("displays the correct images for the project", () => {
render(<Project />);
const mockParams = Promise.resolve({ id: "1" });
render(<Project params={mockParams} />);

// Check that the project image and screenshots are rendered correctly
const projectImage = screen.getByAltText("Project Thumbnail");
Expand Down

0 comments on commit 84fbcdf

Please sign in to comment.