2024-07-01 15:15:43 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { render, fireEvent } from '@testing-library/react-native';
|
|
|
|
import UnitChooser from "../UnitChooser";
|
2024-08-10 19:06:25 +02:00
|
|
|
import { Length } from 'convert';
|
2024-07-01 15:15:43 +02:00
|
|
|
|
|
|
|
describe('UnitChooser', () => {
|
|
|
|
const mockOnChoicePressed = jest.fn();
|
|
|
|
const choices = ['foot', 'inch'] as Length [];
|
|
|
|
|
|
|
|
it('renders correctly', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<UnitChooser choices={choices} onChoicePressed={mockOnChoicePressed} />
|
|
|
|
);
|
|
|
|
|
|
|
|
choices.forEach(choice => {
|
|
|
|
expect(getByText(choice)).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls onChoicePressed when a button is pressed', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<UnitChooser choices={choices} onChoicePressed={mockOnChoicePressed} />
|
|
|
|
);
|
|
|
|
|
|
|
|
fireEvent.press(getByText(choices[0]));
|
|
|
|
|
|
|
|
expect(mockOnChoicePressed).toHaveBeenCalledWith(choices[0]);
|
|
|
|
});
|
|
|
|
});
|