From 3ffbbcff864faec0a2207dca987cba9aa2bdaad9 Mon Sep 17 00:00:00 2001 From: Bryan Lor <103898129+Bryan-Lor@users.noreply.github.com> Date: Fri, 19 Apr 2024 21:07:48 -0400 Subject: [PATCH] Merging CI unit tests into main (#62) * Removed QuickAdd * Update ci.yml testing new path * Removed jest --watchAll to remove infinite unit test idling after success * Added bryan unit tests * Fixed and Added Mohammads Unit Tests --- .github/workflows/ci.yml | 4 +- AugmentedSpace/components/ItemCard.tsx | 19 ++-- .../components/__tests__/CartCard.test.tsx | 90 +++++++++++++++++++ 3 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 AugmentedSpace/components/__tests__/CartCard.test.tsx diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9015013..6638719 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,9 +29,9 @@ jobs: - name: Rory Lange ItemCard Unit Tests run: cd AugmentedSpace && npm test --testPathPattern="components\__tests__\ItemCard.test" - + - name: Bryan Lor LogIn Page Unit Tests run: cd AugmentedSpace && npm test --testPathPattern="app\__tests__\logIn.test" - name: Mohammad Sulaiman CartCard Unit Tests - run: cd AugmentedSpace && npm test --testPathPattern="components\__tests__\CartCard.test" + run: cd AugmentedSpace && npm test --testPathPattern="components\__tests__\CartCard.test" \ No newline at end of file diff --git a/AugmentedSpace/components/ItemCard.tsx b/AugmentedSpace/components/ItemCard.tsx index dc3f70d..2848a25 100644 --- a/AugmentedSpace/components/ItemCard.tsx +++ b/AugmentedSpace/components/ItemCard.tsx @@ -1,9 +1,4 @@ -import { - Image, - Pressable, - Text, - View, -} from "react-native"; +import { Image, Pressable, Text, View } from "react-native"; import { useTheme } from "@react-navigation/native"; import { useEffect, useState } from "react"; import { getDownloadURL, getStorage, ref } from "firebase/storage"; @@ -51,8 +46,7 @@ export default function ItemCard(props: ItemCardProps) { shadowOpacity: 1, }} > - + - + - + ({ + useTheme: jest.fn(), +})); + +jest.mock("firebase/storage", () => ({ + getStorage: jest.fn(), + ref: jest.fn(), + getDownloadURL: jest.fn(), +})); + +jest.mock("expo-router", () => ({ + router: { + push: jest.fn(), + }, +})); + +// Mock theme +const theme = { + colors: { + card: "white", + text: "black", + }, +}; + +beforeEach(() => { + (useTheme as jest.Mock).mockReturnValue(theme); + (getDownloadURL as jest.Mock).mockResolvedValue("http://dummyimage.com"); +}); + +describe("CartCard", () => { + const baseProps = { + itemName: "Test Item", + brandName: "Test Brand", + itemCost: 99, + imagePath: "path/to/image", + onRemove: jest.fn(), + width: 200, + }; + + test("renders correctly", () => { + const { getByText } = render(); + expect(getByText("Test Brand")).toBeTruthy(); + expect(getByText("Test Item")).toBeTruthy(); + expect(getByText("$99")).toBeTruthy(); + }); + + test("calls onRemove when remove button is pressed", () => { + const { getByText } = render(); + const removeButton = getByText("Remove"); + fireEvent.press(removeButton); + expect(baseProps.onRemove).toHaveBeenCalled(); + }); + + test("navigates to item info when pressed", () => { + const { getByText } = render(); + fireEvent.press(getByText("Test Brand")); + expect(router.push).toHaveBeenCalledWith({ + pathname: "/item-info/[items]", + params: { + items: "Test Item", + imageSource: "path/to/image", + itemCost: 99, + brandName: "Test Brand", + }, + }); + }); + + test("applies theme colors correctly", () => { + const { getByText } = render(); + const textComponent = getByText("Test Brand"); + const style = textComponent.props.style; + console.log("Style:", style); + + expect(style).toEqual( + expect.objectContaining([ + { color: "#000" }, + [{ fontWeight: "bold" }, { color: "black" }], + ]) + ); + }); +});