From ab7a43ef84d331ac2b9fb3036be9b6acc503fd19 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 27 Jun 2024 19:00:45 -0700 Subject: [PATCH] covered product editor test cases. --- .../__tests__/ProductEditorItem-test.tsx | 40 +++++++++++++++++++ setup/jest.js | 3 ++ 2 files changed, 43 insertions(+) create mode 100644 components/__tests__/ProductEditorItem-test.tsx create mode 100644 setup/jest.js diff --git a/components/__tests__/ProductEditorItem-test.tsx b/components/__tests__/ProductEditorItem-test.tsx new file mode 100644 index 0000000..d23d88b --- /dev/null +++ b/components/__tests__/ProductEditorItem-test.tsx @@ -0,0 +1,40 @@ +import React from 'react'; +import { render, fireEvent, screen } from '@testing-library/react-native'; +import { ProductEditorItem } from '../ProductEditorItem'; +import { Product } from '@/lib/product'; +import { area } from 'enheter'; + +describe('ProductEditorItem', () => { + const mockProduct = new Product( + 25, + area("squareFoot", 4 * 8), + {"name": "Product 1"}, + ) + + const mockOnProductUpdated = jest.fn(); + const mockOnProductDeleted = jest.fn(); + + it('renders correctly', () => { + render( + + ); + expect(screen.getAllByText('Product 1').length).toEqual(1); + }); + + it('calls onProductUpdated when TouchableHighlight is pressed', () => { + render( + + ); + fireEvent.press(screen.getByText("Product 1")); + expect(screen.getByText('name')).toBeTruthy(); + expect(screen.getAllByText('Product 1').length).toEqual(2); + }); +}); diff --git a/setup/jest.js b/setup/jest.js new file mode 100644 index 0000000..b810e31 --- /dev/null +++ b/setup/jest.js @@ -0,0 +1,3 @@ +jest.mock('@react-native-async-storage/async-storage', () => + require('@react-native-async-storage/async-storage/jest/async-storage-mock') +); \ No newline at end of file