import React, { Fragment } from 'react';
import { render, mount, shallow } from 'enzyme';
import Radio, { RadioGroup } from '../index';
describe('Snapshots', () => {
it('Radio unchecked', () => {
const wrapper = render();
expect(wrapper).toMatchSnapshot();
});
it('Radio checked', () => {
const wrapper = render();
expect(wrapper).toMatchSnapshot();
});
it('Radio disabled', () => {
const wrapper = render();
expect(wrapper).toMatchSnapshot();
});
it('Radio group disabled', () => {
const wrapper = render(
{RadioB => (
)}
);
expect(wrapper).toMatchSnapshot();
});
it('Radio group with child disabled', () => {
const wrapper = render(
{RadioB => (
)}
);
expect(wrapper).toMatchSnapshot();
});
it('Render children', () => {
const wrapper = render(
Hello
);
expect(wrapper).toMatchSnapshot();
});
});
describe('Functions', () => {
it('trigger onChange when clicked', () => {
const clickHandler = jest.fn();
const wrapper = shallow(
);
wrapper.find('input').simulate('change');
expect(clickHandler).toHaveBeenCalledTimes(1);
});
});
describe('RadioGroup', () => {
it('accept and call children function', () => {
const f = jest.fn();
mount({f});
expect(f).toHaveBeenCalledTimes(1);
});
it('render RadioButton class as children', () => {
const wrapper = mount(
{RadioButton => (
)}
);
expect(wrapper.find(Radio)).toHaveLength(3);
});
it('call onChange when selected option changes', () => {
const changeHandler = jest.fn();
const wrapper = mount(
{RadioButton => (
Wallet
Cash
)}
);
wrapper
.find(Radio)
.filter({ value: 'wallet' })
.find('input')
.simulate('change');
expect(changeHandler).toHaveBeenCalledWith('wallet');
});
});