generated from UoaWDCC/react-template
-
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.
UADS-63 test: Test cases for ExecCard component
- Loading branch information
1 parent
6551a12
commit 8f05c7a
Showing
2 changed files
with
68 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
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,20 +1,74 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import ExecCard from "../ExecCard"; | ||
import execImage from "../../assets/placeholder.png" | ||
import execImage from "../../assets/placeholder.png"; | ||
import { ExecType } from "../../utils/FrontendTypes"; | ||
|
||
describe("Exec Card Component", () => { | ||
const exec: ExecType = { | ||
name: "Kai Hirafune", | ||
const execs: ExecType[] = [ | ||
{ | ||
name: "Exec 1", | ||
role: "President", | ||
image: execImage | ||
}; | ||
|
||
it("Renders the ExecCard component with correct name and role", () => { | ||
render(<ExecCard exec={exec} />); | ||
|
||
expect(screen.getByText("Kai Hirafune")).toBeInTheDocument(); | ||
expect(screen.getByText("President")).toBeInTheDocument(); | ||
}); | ||
image: execImage, | ||
}, | ||
{ | ||
name: "", // Missing Name | ||
role: "Vice-President", | ||
image: execImage, | ||
}, | ||
{ | ||
name: "Exec 3", | ||
role: "", // Missing Role | ||
image: execImage, | ||
}, | ||
{ | ||
name: "Exec 4", | ||
role: "Treasurer", | ||
image: "", // Missing Image | ||
}, | ||
]; | ||
|
||
describe("Exec Card Component", () => { | ||
it("Renders the ExecCard component with correct name, role and image", () => { | ||
render(<ExecCard exec={execs[0]} />); | ||
|
||
expect(screen.getByText("Exec 1")).toBeInTheDocument(); | ||
expect(screen.getByText("President")).toBeInTheDocument(); | ||
|
||
// Check if background image is correctly applied | ||
const cardElement = screen.getByTestId("execCard"); | ||
expect(cardElement).toHaveStyle(`backgroundImage: url(${execs[0].image})`); | ||
}); | ||
|
||
it("Missing name for exec is not rendered", () => { | ||
render(<ExecCard exec={execs[1]} />); | ||
|
||
expect(screen.queryByText("Exec 2")).not.toBeInTheDocument(); | ||
expect(screen.getByText("Vice-President")).toBeInTheDocument(); | ||
|
||
// Check if background image is correctly applied | ||
const cardElement = screen.getByTestId("execCard"); | ||
expect(cardElement).toHaveStyle(`backgroundImage: url(${execs[1].image})`); | ||
}); | ||
|
||
it("Missing role for exec is not rendered", () => { | ||
render(<ExecCard exec={execs[2]} />); | ||
|
||
expect(screen.queryByText("Exec 3 Role")).not.toBeInTheDocument(); | ||
expect(screen.getByText("Exec 3")).toBeInTheDocument(); | ||
|
||
// Check if background image is correctly applied | ||
const cardElement = screen.getByTestId("execCard"); | ||
expect(cardElement).toHaveStyle(`backgroundImage: url(${execs[2].image})`); | ||
}); | ||
|
||
it("Missing image for exec is not rendered", () => { | ||
render(<ExecCard exec={execs[3]} />); | ||
|
||
expect(screen.getByText("Exec 4")).toBeInTheDocument(); | ||
expect(screen.getByText("Treasurer")).toBeInTheDocument(); | ||
|
||
// Check if background image is not present and url is empty | ||
const cardElement = screen.getByTestId("execCard"); | ||
expect(cardElement).toHaveStyle(`backgroundImage: url(${execs[3].image})`); | ||
}); | ||
}); |