Skip to content

Commit

Permalink
test: Test cases for PartnerCard component
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsheel12 committed Jul 4, 2024
1 parent 9de015b commit c50bdb7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion web/__test__/components/ExecCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { describe, expect, it } from "vitest";
import { render, screen } from "@testing-library/react";
import ExecCard from "../../src/components/ExecCard";
import React from "react";
import { Exec } from "../../src/types/types";

const mockExec = {
const mockExec: Exec = {
id: 1,
image: "/uploads/john_doe.jpg",
position: "President",
Expand Down
45 changes: 45 additions & 0 deletions web/__test__/components/PartnerCard.test.tsx
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
});
});

0 comments on commit c50bdb7

Please sign in to comment.