PliWould/components/__tests__/AreaInput-test.tsx

32 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-07-01 17:05:24 +02:00
import { render, fireEvent, screen } from '@testing-library/react-native';
2024-07-01 15:15:43 +02:00
import { AreaInput } from '../AreaInput';
describe('AreaInput', () => {
it('renders correctly', () => {
2024-07-01 17:05:24 +02:00
render(<AreaInput lengthLabel='length' widthLabel='width' />);
const lengthInput = screen.getByLabelText('length');
const widthInput = screen.getByLabelText('width');
2024-07-01 15:15:43 +02:00
expect(lengthInput).toBeTruthy();
expect(widthInput).toBeTruthy();
});
it('calls onValueSet when a value is entered', () => {
2024-07-01 17:05:24 +02:00
const onMeasurementSetMock = jest.fn();
render(<AreaInput onMeasurementSet={onMeasurementSetMock} lengthLabel='length' widthLabel='width' defaultValue={{l: 4, w:4, u: "inch"}}/>);
const lengthInput = screen.getByLabelText('length');
const widthInput = screen.getByLabelText('width');
2024-07-01 15:15:43 +02:00
fireEvent.changeText(lengthInput, '10');
2024-07-01 17:05:24 +02:00
expect(onMeasurementSetMock).toHaveBeenCalledWith({
l: 10,
w: 4,
u: "inch"
});
fireEvent.changeText(widthInput, '10');
expect(onMeasurementSetMock).toHaveBeenCalledWith({
l: 10,
w: 10,
u: "inch"
});
2024-07-01 15:15:43 +02:00
});
});