import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import UnitChooser from "../UnitChooser";
import { Length } from 'convert';

describe('UnitChooser', () => {
  const mockOnChoicePressed = jest.fn();
  const choices = ['foot', 'inch'] as Length [];

  it('renders correctly', () => {
    const { getByText } = render(
      <UnitChooser choices={choices} onUnitSet={mockOnChoicePressed} />
    );

    choices.forEach(choice => {
      expect(getByText(choice)).toBeTruthy();
    });
  });

  it('calls onChoicePressed when a button is pressed', () => {
    const { getByText } = render(
      <UnitChooser choices={choices} onUnitSet={mockOnChoicePressed} />
    );

    fireEvent.press(getByText(choices[0]));

    expect(mockOnChoicePressed).toHaveBeenCalledWith(choices[0]);
  });
});
