import Select from '../';
const {renderIntoDocument, Simulate} = TestUtils;
import {identity} from 'lodash/lang';
import fixture from './fixture';
//onChangeSpy = sinon.spy();

describe('The select ', () => {
    describe('when called with no props', () => {
        let component;
        before(
            () => {
                const shallowRenderer = TestUtils.createRenderer();
                shallowRenderer.render(<Select/>);
                component = shallowRenderer.getRenderOutput();
            }
        );
        it.skip('should render an empty select', ()=>{

        });
    });
    describe('when called with minimal props', () => {
        let component, domNode;
        const mockValues = fixture.VALUES;
        before(
            () => {
                component = renderIntoDocument(<Select name='selectName' values={mockValues} onChange={identity}/>);
                domNode = ReactDOM.findDOMNode(component);
            }
        );
        it('should render an empty select', () => {
            expect(domNode.tagName).to.equal('DIV');
            expect(domNode.getAttribute('data-focus')).to.equal('select');
            expect(ReactDOM.findDOMNode(component.refs.htmlSelect).tagName).to.equal('SELECT');
        });
        it('should not have a value', () => {
            expect(component.getValue()).to.equal(null);
        });
    });
    describe('when a value is provided', ()=>{
        const {VALUE, VALUES} = fixture;
        let component, domNode;
        before(()=>{
            component = renderIntoDocument(<Select name='selectName' onChange={identity} value={VALUE} values={VALUES} />);
        });
        it('should return the value when provided as a props', ()=> {
            expect(component.getValue()).to.equal(VALUE);
        });
        it('should render the value in the DOM', ()=>{
            expect(ReactDOM.findDOMNode(component.refs.htmlSelect).value).to.equal(`${VALUE}`);
        });
    });
    describe('when the user select a new value', ()=>{
        const {VALUE, VALUES} = fixture;
        let onChangeSpy, component;
        before(
            () => {
                onChangeSpy = sinon.spy();
                component = renderIntoDocument(<Select name='selectName' onChange={identity} value={VALUE} values={VALUES} />);
            }
        );
        it('should call onChange with the new value', ()=>{
            Simulate.change(ReactDOM.findDOMNode(component.refs.htmlSelect), {target: {value: VALUE}});
        });
    })
});

@@ -2246,39 +2246,42 @@
 Name' onChange=%7B
-identit
+onChangeSp
 y%7D value=%7BVALUE%7D
@@ -2487,24 +2487,146 @@
 : VALUE%7D%7D);%0A
+            expect(onChangeSpy).to.have.been.called.once;%0A            expect(onChangeSpy).to.have.been.calledWith(VALUE);%0A
         %7D);%0A

update spy