43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import React from 'react';
|
|
import { render, fireEvent } from '@testing-library/react-native';
|
|
import { Provider } from 'react-redux';
|
|
import { store } from '@/app/store';
|
|
import ProductCalculatorSelector from '@/components/ProductCalculatorSelector';
|
|
|
|
describe('ProductCalculatorSelector', () => {
|
|
it('renders correctly', () => {
|
|
const { getByText } = render(
|
|
<Provider store={store}>
|
|
<ProductCalculatorSelector />
|
|
</Provider>
|
|
);
|
|
|
|
expect(getByText('Please select a product')).toBeTruthy();
|
|
});
|
|
|
|
it('updates price when measurement is set', () => {
|
|
const { getByTestId, getByText } = render(
|
|
<Provider store={store}>
|
|
<ProductCalculatorSelector />
|
|
</Provider>
|
|
);
|
|
|
|
// Assume there is a product with a priceFor function that returns 100
|
|
const product = {
|
|
priceFor: jest.fn().mockReturnValue(100),
|
|
};
|
|
|
|
// Assume there are units for measurement
|
|
const units = ['cm', 'in'];
|
|
|
|
// Assume there is a measurement input
|
|
const measurementInput = getByTestId('measurement-input');
|
|
|
|
// Simulate user input
|
|
fireEvent.changeText(measurementInput, '10');
|
|
|
|
// Check if the price has been updated
|
|
expect(getByText('Price: 100')).toBeTruthy();
|
|
});
|
|
});
|