'use strict'

import { React, TestUtils, expect, chai, spies, defaultProps } from '../config'

import SwatchesGroupComponent from '../../src/components/swatches/SwatchesGroup'

let props

describe('SwatchesGroup', () => {

  beforeEach(() => {
    props = defaultProps
  })

  it('should pass up data onClick', () => {
    props.onClick = chai.spy((data) => {
      expect(data).to.equal('#333')
    })
    const SwatchesGroup = TestUtils.renderIntoDocument(<SwatchesGroupComponent {...props} group={['#333']} />)
    SwatchesGroup.handleClick('#333')
    expect(props.onClick).to.have.been.called
  })

  it('should render SwatchesGroup for each top-level array passed to props.colors', () => {
    const SwatchesGroup = TestUtils.renderIntoDocument(<SwatchesGroupComponent {...props} group={['#333', '#fff', '#aaa', '#ddd']} />)
    let colors = SwatchesGroup.refs.group._reactInternalComponent._renderedChildren
    let colorCount = 0
    for (var color in colors) {
      colorCount += 1
    }

    expect(SwatchesGroup.props.group).to.exist
    expect(colorCount).to.equal(4)
  })

})

@@ -22,16 +22,26 @@
 %7B React,
+ ReactDOM,
  TestUti
@@ -851,161 +851,78 @@
 olor
-s = SwatchesGroup.refs.group._reactInternalComponent._renderedChildren%0A    let colorCount = 0%0A    for (var color in colors) %7B%0A      colorCount += 1%0A    %7D
+Count = ReactDOM.findDOMNode(SwatchesGroup.refs.group).children.length
 %0A%0A  

Make SwatchesGroup test pass