32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { render, fireEvent, screen } from '@testing-library/react-native';
|
|
import { AreaInput } from '../AreaInput';
|
|
|
|
describe('AreaInput', () => {
|
|
it('renders correctly', () => {
|
|
render(<AreaInput lengthLabel='length' widthLabel='width' />);
|
|
const lengthInput = screen.getByLabelText('length');
|
|
const widthInput = screen.getByLabelText('width');
|
|
expect(lengthInput).toBeTruthy();
|
|
expect(widthInput).toBeTruthy();
|
|
});
|
|
|
|
it('calls onValueSet when a value is entered', () => {
|
|
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');
|
|
fireEvent.changeText(lengthInput, '10');
|
|
expect(onMeasurementSetMock).toHaveBeenCalledWith({
|
|
l: 10,
|
|
w: 4,
|
|
u: "inch"
|
|
});
|
|
fireEvent.changeText(widthInput, '10');
|
|
expect(onMeasurementSetMock).toHaveBeenCalledWith({
|
|
l: 10,
|
|
w: 10,
|
|
u: "inch"
|
|
});
|
|
});
|
|
});
|