covered product editor test cases.
This commit is contained in:
parent
dc9cfad401
commit
ab7a43ef84
40
components/__tests__/ProductEditorItem-test.tsx
Normal file
40
components/__tests__/ProductEditorItem-test.tsx
Normal 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
3
setup/jest.js
Normal file
@ -0,0 +1,3 @@
|
||||
jest.mock('@react-native-async-storage/async-storage', () =>
|
||||
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
|
||||
);
|
Loading…
Reference in New Issue
Block a user