import React from 'react'
import renderer from 'react-test-renderer'
import { mount } from 'enzyme'
import { ConfirmButton, ConfirmButtonState } from '..'

describe('packages/ui', () => {
  it('renders correctly', () => {
    const saveFnc = jest.fn()
    const tree = renderer
      .create(
        <ConfirmButton onClick={saveFnc} dataTestId="simple-confirm-btn" />
      )
      .toJSON()
    expect(tree).toMatchSnapshot()
  })

  it('renders loader when isLoading is true', () => {
    const saveFnc = jest.fn()
    const tree = renderer
      .create(
        <ConfirmButton
          onClick={saveFnc}
          dataTestId="loading-button"
          buttonState={ConfirmButtonState.Loading}
        />
      )
      .toJSON()
    expect(tree).toMatchSnapshot()
  })

  it('triggers the onClick function', () => {
    const saveFnc = jest.fn()
    const wrapper = mount(
      <ConfirmButton onClick={saveFnc} dataTestId="simple-confirm-btn" />
    )
    wrapper.find('.ui-btn-save').simulate('click')
    expect(saveFnc).toHaveBeenCalled()
  })
})
