import React from 'react'
import 'react-native'
import renderer from 'react-test-renderer'
import { render, fireEvent } from '@testing-library/react-native'
import { Home } from './Home'

describe('Home Screen Component', () => {
  it('renders correctly', () => {
    // when we create the component then it should render correctly
    const instance = renderer.create(<Home onNextPressed={() => null} />)
    expect(instance.root.type).toBe(Home)
  })

  it('should call the onNextPressed when the next button is pressed', () => {
    // given ... we have a Home screen component
    // ... we have a next pressed handler
    const onNextPressed = jest.fn()
    const { getByTestId } = render(<Home onNextPressed={onNextPressed} />)

    // when ... we click the next button
    fireEvent.press(getByTestId('nextButton'))

    // then ... onNextPressed should have been called as expected
    expect(onNextPressed).toHaveBeenCalled()
  })
})
