Skip to content

Commit

Permalink
add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alissacrane-cb committed Oct 16, 2024
1 parent ffab047 commit 80d0209
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/components/OnchainStoreItem.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import OnchainStoreItem from "./OnchainStoreItem";

const mockProduct = {
id: "1",
name: "Sample Product",
price: 19.99,
image: "https://example.com/image.jpg",
};

vi.mock("./QuantityInput", () => {
return {
default: ({ productId }: { productId: string }) => (
<input data-testid={`quantity-input-${productId}`} />
),
};
});

vi.mock("next/image", () => {
return {
default: ({
src,
alt,
width,
height,
}: {
src: string;
alt: string;
width: number;
height: number;
}) => <img src={src} alt={alt} width={width} height={height} />,
};
});

describe("OnchainStoreItem", () => {
it("should render product information correctly", () => {
render(<OnchainStoreItem {...mockProduct} />);

expect(screen.getByText("Sample Product")).toBeInTheDocument();
expect(screen.getByText("19.99 USDC")).toBeInTheDocument();
const imageElement = screen.getByAltText("123");
expect(imageElement).toBeInTheDocument();
expect(imageElement).toHaveAttribute("src", mockProduct.image);
expect(imageElement).toHaveAttribute("width", "400");
expect(imageElement).toHaveAttribute("height", "400");
expect(screen.getByTestId("quantity-input-1")).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
Expand Down

0 comments on commit 80d0209

Please sign in to comment.