import { shallow, mount } from 'enzyme';
import React from 'react';
import sinon from 'sinon';
import { Radio, RadioOption } from 'web-foundation';

describe('<Radio />', function() {
    const options = [
        new RadioOption({ title: 'a', value: 'a' }),
        new RadioOption({ title: 'b', value: 'b' })
    ];

    it('should initialize properly', function() {
        const wrapper = shallow(<Radio />);

        expect(wrapper.hasClass('radio')).to.be.true;
    });

    it('should initialize from props', function() {
        const wrapper = shallow(
            <Radio value={ options[0].value }
                items={ options } />);

        expect(wrapper.find('.option')).to.have.length(options.length);
    });

    it('should call me back', function() {
        const spy = sinon.spy(),
            wrapper = mount(
                <Radio onSelect={ spy }
                    value={ options[0].value }
                    items={ options } />);

        wrapper.find('.option').at(1).simulate('click');

        expect(spy.callCount).to.equal(1);
        expect(spy.calledWith(options[1].value));
    });

    it('should allow more classes', function() {
        const someClass = 'abcdef',
            wrapper = shallow(<Radio className={ someClass }/>);

        expect(wrapper.hasClass(someClass)).to.be.true;
    });

    it('should change selected option through props', function() {
        const wrapper = mount(
            <Radio value={ options[0].value }
                items={ options } />);

        expect(wrapper.state('at')).to.equal(0);

        wrapper.setProps({ value: options[1].value });

        expect(wrapper.state('at')).to.equal(1);
    });
});
