diff --git a/__fixtures__/initialProducts.ts b/__fixtures__/initialProducts.ts new file mode 100644 index 0000000..f1cbbc0 --- /dev/null +++ b/__fixtures__/initialProducts.ts @@ -0,0 +1,11 @@ +import { Product } from "@/lib/product"; +import { area, length } from "enheter"; + +export const products = [ + // Sheet goods + new Product(35, area("squareFoot", 4 * 8), { name: "Plywood" }), + new Product(45, area("squareFoot", 4 * 8), { name: "OSB" }), + new Product(45, area("squareFoot", 4 * 8), { name: "MDF" }), + // Beams and trim + new Product(45, length("foot", 1), { name: "trim" }), +]; \ No newline at end of file diff --git a/__mocks__/@react-native-async-storage/async-storage.js b/__mocks__/@react-native-async-storage/async-storage.js new file mode 100644 index 0000000..a2542e9 --- /dev/null +++ b/__mocks__/@react-native-async-storage/async-storage.js @@ -0,0 +1 @@ +export * from '@react-native-async-storage/async-storage/jest/async-storage-mock'; \ No newline at end of file diff --git a/components/ProductEditor.tsx b/components/ProductEditor.tsx index 1fbe551..3918e23 100644 --- a/components/ProductEditor.tsx +++ b/components/ProductEditor.tsx @@ -1,13 +1,11 @@ import { useAppDispatch, useAppSelector } from "@/app/store" import { deleteProduct, selectProducts, updateProduct } from "@/features/product/productSlice" import { Product } from "@/lib/product"; -import { FlatListComponent, StyleSheet, Text } from "react-native"; -import { FlatList } from "react-native-reanimated/lib/typescript/Animated"; -import { SafeAreaView } from "react-native-safe-area-context"; +import { FlatList, SafeAreaView, StyleSheet, Text } from "react-native"; import { ProductEditorItem } from "./ProductEditorItem"; import React from "react"; -export const ProductEditor = () => { +export const ProductEditor = ({}) => { const products = useAppSelector(selectProducts) as Product []; const dispatch = useAppDispatch(); @@ -23,6 +21,7 @@ export const ProductEditor = () => { return ( + Hello { + it("renders correctly", async () => { + const {store} = renderWithProviders(, { + products: fixtures, + }); + + const products = store.getState(); + + // Check if the product names are rendered + expect(screen.getByText(products[0].attributes.name as string)).toBeTruthy(); + expect(screen.getByText(products[1].attributes.name as string)).toBeTruthy(); + expect(screen.getByText(products[2].attributes.name as string)).toBeTruthy(); + expect(screen.getByText(products[3].attributes.name as string)).toBeTruthy(); + }); +}); diff --git a/features/product/initialProducts.ts b/features/product/initialProducts.ts deleted file mode 100644 index b267c57..0000000 --- a/features/product/initialProducts.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Price, Product } from "@/lib/product"; -import { area, length } from "enheter"; - -export default [ - // Sheet goods - new Product(new Price("USD", 35), area("squareFoot", 4 * 8), {name: "Plywood"}), - new Product(new Price("USD", 45), area("squareFoot", 4 * 8), {name: "OSB"}), - new Product(new Price("USD", 45), area("squareFoot", 4 * 8), {name: "MDF"}), - // Beams and trim - new Product(new Price("USD", 1), length("foot", 1), {name: "trim"}), -] \ No newline at end of file diff --git a/components/__tests__/util.tsx b/lib/rendering.tsx similarity index 76% rename from components/__tests__/util.tsx rename to lib/rendering.tsx index b097f81..5917f4f 100644 --- a/components/__tests__/util.tsx +++ b/lib/rendering.tsx @@ -2,24 +2,19 @@ import { RenderOptions, render } from "@testing-library/react-native"; import { PropsWithChildren, ReactElement } from "react"; import { Provider } from "react-redux"; import { setupStore, RootState } from "@/app/store"; -import { Price, Product } from "@/lib/product"; -import { area, length } from "enheter"; +import { Product } from "@/lib/product"; +import React from "react"; export interface ExtendedRenderOptions extends Omit { preloadedState?: Partial; store?: any; // TODO } -const basicState = { - products: [ - new Product(20.00, length("foot", 5), {name: "Track"}), - new Product(20.00, area("squareFoot", 5), {name: "Shelf"}), - ] -} - export function renderWithProviders( ui: ReactElement, - preloadedState = basicState, + preloadedState = { + products: [] as Product [] + }, extendedRenderOptions: ExtendedRenderOptions = {}, ) { const {