generated from UoaWDCC/ssr-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.
test: Test cases for PartnerCard component
- Loading branch information
1 parent
9de015b
commit c50bdb7
Showing
2 changed files
with
47 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { fireEvent, render, screen } from "@testing-library/react"; | ||
import PartnerCard from "../../src/components/PartnerCard"; | ||
import React from "react"; | ||
import { Partner } from "../../src/types/types"; | ||
|
||
const mockPartner: Partner = { | ||
id: 1, | ||
type: "Gold", | ||
name: "The Kebab and Chicken House", | ||
location: "17 Mount Street", | ||
description: "20% off Everything", | ||
image: "/uploads/kebab.jpg", | ||
}; | ||
|
||
describe("PartnerCard", () => { | ||
it("renders PartnerCard with correct data", () => { | ||
render(<PartnerCard partner={mockPartner} colour="#F3CF0B" />); | ||
|
||
// Check if the elements are rendered correctly | ||
expect(screen.getByAltText("Partner Image")).toBeInTheDocument(); | ||
const partnerImage = screen.getByAltText("Partner Image"); | ||
expect(partnerImage).toHaveAttribute("src", mockPartner.image); | ||
expect(screen.getByText("The Kebab and Chicken House")).toBeInTheDocument(); | ||
expect(screen.getByText("17 Mount Street")).toBeInTheDocument(); | ||
expect(screen.getByText("20% off Everything")).toBeInTheDocument(); | ||
}); | ||
|
||
it("opens Google Maps with the correct query when 'View' button is clicked", () => { | ||
render(<PartnerCard partner={mockPartner} colour="#F3CF0B" />); | ||
|
||
const originalOpen = window.open; | ||
window.open = vi.fn(); | ||
|
||
const viewButton = screen.getByText("View"); | ||
fireEvent.click(viewButton); | ||
|
||
expect(window.open).toHaveBeenCalledWith( | ||
"https://www.google.com/maps/search/?api=1&query=17%20Mount%20Street", | ||
"_blank" | ||
); | ||
|
||
window.open = originalOpen; // Restore original window.open | ||
}); | ||
}); |