/// <reference types="jest-enzyme" />
/// <reference path="../../../../../utilities/jest/extensions.ts" />

import * as fc from 'fast-check'
import * as Enzyme from 'enzyme'
import * as React from 'react'
import * as FeatherIcon from 'react-feather'
import paramCase from 'param-case'
import Icon from '.'

const FEATHER_ICONS = Object.keys(FeatherIcon).map((k) => paramCase(k))

it('should exist', () => {
  expect(Icon).toBeDefined()
})

it('should be a component', () => {
  expect(Icon).toBeComponent()
})

it('should render without crashing given required props', () => {
  expect(() => <Icon name="foo" />).not.toThrow()
})

describe('on XML icons', () => {
  test.each(FEATHER_ICONS)('should render the %p XML icon', (name) => {
    const wrapper = Enzyme.shallow(<Icon name={name} />)

    expect(wrapper).toHaveLength(1)
  })
})

it('should render null for an unknown icon name', () => {
  fc.assert(
    fc.property(fc.string().filter((v) => ![...FEATHER_ICONS].includes(paramCase(v.toLowerCase()))), (v) => {
      const wrapper = Enzyme.shallow(<Icon name={v} />)

      expect(wrapper.getElement()).toBe(null)
    }),
  )
})
