import { shallow } from 'enzyme';
import React from 'react';
import sinon from 'sinon';
import { Switch } from 'web-foundation';

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

        expect(wrapper.hasClass('switch')).to.be.true;
        expect(wrapper.hasClass('active')).to.be.false;
    });

    it('should initialize from props', function() {
        const wrapper = shallow(<Switch value />);

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

    it('should update from props', function() {
        const wrapper = shallow(<Switch value />);

        expect(wrapper.hasClass('active')).to.be.true;

        wrapper.setProps({ value: false });

        expect(wrapper.hasClass('active')).to.be.false;

        wrapper.setProps({ beans: 'pinto' });

        expect(wrapper.hasClass('active')).to.be.false;
    });

    it('should toggle on clicks', function() {
        const wrapper = shallow(<Switch />);

        expect(wrapper.hasClass('active')).to.be.false;

        wrapper.simulate('click');

        expect(wrapper.hasClass('active')).to.be.true;

        wrapper.simulate('click');

        expect(wrapper.hasClass('active')).to.be.false;
    });

    it('should let you know when it has changed', function() {
        const change = sinon.spy(),
            wrapper = shallow(<Switch onChange={ change } />);

        wrapper.simulate('click');

        expect(change.calledOnce).to.be.true;
    });
});
