import React from 'react';
import { withFixedChangeHandler } from './withFixedChangeHandler';
import { mount } from 'enzyme';

describe('Shared/HOCs/withFixedChangeHandler', () => {
    it('does not call the onChange if the values are the same', () => {
        const onChange = jest.fn();
        const FixedInput = withFixedChangeHandler(props => <input {...props} />);
        const wrapper = mount(<FixedInput onChange={onChange} value={5} />);
        wrapper.find('input').simulate('change', { target: { value: 5 } });
        expect(onChange).not.toHaveBeenCalled();
    });
    it('calls the onChange if the value has changed', () => {
        const onChange = jest.fn();
        const FixedInput = withFixedChangeHandler(props => <input {...props} />);
        const wrapper = mount(<FixedInput onChange={onChange} value={5} />);
        wrapper.find('input').simulate('change', { target: { value: 2 } });
        expect(onChange).toHaveBeenCalled();
    });
});
