covered product editor test cases.

This commit is contained in:
Jordan 2024-06-27 19:00:45 -07:00
parent dc9cfad401
commit ab7a43ef84
2 changed files with 43 additions and 0 deletions

View File

@ -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(
<ProductEditorItem
product={mockProduct}
onProductUpdated={mockOnProductUpdated}
onProductDeleted={mockOnProductDeleted}
/>
);
expect(screen.getAllByText('Product 1').length).toEqual(1);
});
it('calls onProductUpdated when TouchableHighlight is pressed', () => {
render(
<ProductEditorItem
product={mockProduct}
onProductUpdated={mockOnProductUpdated}
onProductDeleted={mockOnProductDeleted}
/>
);
fireEvent.press(screen.getByText("Product 1"));
expect(screen.getByText('name')).toBeTruthy();
expect(screen.getAllByText('Product 1').length).toEqual(2);
});
});

3
setup/jest.js Normal file
View File

@ -0,0 +1,3 @@
jest.mock('@react-native-async-storage/async-storage', () =>
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
);