import { mount } from 'enzyme';
import React from 'react';
import { RadioButtonInput } from './RadioButtonInput';
const noop = () => {};
describe('', () => {
it('renders radio button inputs', () => {
const value = 'b';
const options = ['a', 'b', 'c', 'd'];
const wrapper = mount();
expect(wrapper.find('.RadioButtonInput').length).toBe(1);
expect(wrapper.find('input[type="radio"]').length).toBe(4);
});
it('updates the selected item using the value prop', () => {
const value = 'b';
const options = ['a', 'b', 'c', 'd'];
const wrapper = mount();
expect(wrapper.find('input[type="radio"][checked=true]').getDOMNode().value).toBe('b');
wrapper.setProps({ value: 'c' });
expect(wrapper.find('input[type="radio"][checked=true]').getDOMNode().value).toBe('c');
});
it('wires the onChange handler to the radios', () => {
const value = 'b';
const options = ['a', 'b', 'c', 'd'];
const spy = jasmine.createSpy('onChange');
const wrapper = mount();
wrapper.find('input[type="radio"][value="c"]').simulate('change', { target: { value: 'c' } });
expect(spy).toHaveBeenCalledTimes(1);
});
describe('defaultValue prop', () => {
it('causes the onChange handler to be called with a default value when no value is set', () => {
const value = undefined as string;
const options = ['a', 'b', 'c', 'd'];
const spy = jasmine.createSpy('onChange');
mount();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.calls.mostRecent().args[0].target.value).toBe('a');
});
it('causes the onChange handler to be called with a default value when an invalid value is set', () => {
const value = 'x';
const options = ['a', 'b', 'c', 'd'];
const spy = jasmine.createSpy('onChange');
mount();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy.calls.mostRecent().args[0].target.value).toBe('a');
});
it('does not call the onChange handler if no defaultValue is provided', () => {
const value = 'x';
const options = ['a', 'b', 'c', 'd'];
const spy = jasmine.createSpy('onChange');
mount();
expect(spy).not.toHaveBeenCalled();
});
});
});