import React from 'react'
import { mount } from '../../test/utils'

import { Link } from '../Link'

describe('<Link />', () => {
  describe('children', () => {
    it('renders its children', () => {
      const mockChildren = 'mock_children'
      const link = mount(<Link>{mockChildren}</Link>)
      expect(link.find('button')).toContainReactText(mockChildren)
    })
  })

  describe('url', () => {
    it('renders a <a> with rel and target when using external', () => {
      const mockUrl = 'https://palenca.com'
      const button = mount(<Link external url={mockUrl} />)
      expect(button).toContainReactComponent('a', {
        rel: 'noopener noreferrer',
        target: '_blank',
        href: mockUrl
      })
    })
  })

  describe('onClick()', () => {
    it('is called when the link is clicked', () => {
      const onClickSpy = jest.fn()
      const link = mount(<Link onClick={onClickSpy} />)
      link.find('button')!.trigger('onClick')
      expect(onClickSpy).toHaveBeenCalledTimes(1)
    })
  })
})
