import createComponent from '../../../modules/bindings/react/createComponent'
import createRenderer from '../../../modules/createRenderer'

describe('Creating Components from Fela rules', () => {
  it('should return a Component', () => {
    const rule = props => ({ color: props.color, fontSize: 16 })
    const component = createComponent(rule)

    expect(component).to.be.a.function
  })

  it('should render fela rules depending on the passed props', () => {
    const rule = props => ({ color: props.color, fontSize: 16 })
    const component = createComponent(rule)

    const renderer = createRenderer()

    const element = component({ color: 'black' }, { renderer })

    expect(element.type).to.eql('div')

    expect(element.props.className).to.eql('a b')
    expect(renderer.rules).to.eql('.a{color:black}.b{font-size:16}')
  })

  it('should use the theme for static rendering by default', () => {
    const rule = props => ({
      color: props.theme.color,
      fontSize: 16
    })
    const component = createComponent(rule)
    const renderer = createRenderer()

    const element = component({ }, {
      renderer,
      theme: {
        color: 'red'
      }
    })

    expect(element.type).to.eql('div')

    expect(element.props.className).to.eql('a b')
    expect(renderer.rules).to.eql('.a{color:red}.b{font-size:16}')
  })

  it('should only pass explicit props to the element', () => {
    const rule = props => ({ color: props.color, fontSize: 16 })
    const component = createComponent(rule, 'div', [ 'onClick' ])

    const renderer = createRenderer()

    const element = component({ onClick: false, onHover: true }, {
      renderer
    })

    expect(element.props.onClick).to.eql(false)
    expect(element.props.onHover).to.eql(undefined)
  })

  it('should only use passed props to render Fela rules', () => {
    const rule = props => ({
      color: props.foo && props.color,
      fontSize: 16
    })
    const component = createComponent(rule, 'div', [ 'foo' ])

    const renderer = createRenderer()

    const element = component({ foo: true, color: 'black' }, {
      renderer
    })

    expect(element.props.foo).to.eql(true)
    expect(renderer.rules).to.eql('.a{color:black}.b{font-size:16}')
  })

  it('should only use the rule name as displayName', () => {
    const Button = props => ({ color: 'red', fontSize: 16 })
    const component = createComponent(Button)

    expect(component.displayName).to.eql('Button')
  })
})

@@ -1765,32 +1765,457 @@
 ndefined)%0A  %7D)%0A%0A
+  it('should pass all props to the element', () =%3E %7B%0A    const rule = props =%3E (%7B color: props.color, fontSize: 16 %7D)%0A    const component = createComponent(rule, 'div', props =%3E props)%0A%0A    const renderer = createRenderer()%0A%0A    const element = component(%7B onClick: false, onHover: true %7D, %7B%0A      renderer%0A    %7D)%0A%0A    expect(element.props.onClick).to.eql(false)%0A    expect(element.props.onHover).to.not.eql(undefined)%0A  %7D)%0A%0A
   it('should onl

add test for new createComponent prop passthrough