// @ts-ignore import { configure, shallow } from 'enzyme'; // @ts-ignore import Adapter from 'enzyme-adapter-react-16'; import * as React from 'react'; import { TouchableOpacity, View } from 'react-native'; import renderer from 'react-test-renderer'; import MDCodebox from '../../code-box/index'; import MDCountdown from '../countdown'; import MDCaptcha from '../index'; configure({ adapter: new Adapter() }); it('renders correctly with defaults', () => { const component = renderer.create().toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with title', () => { const component = renderer.create().toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with maxlength', () => { const component = renderer .create() .toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha without maxlength', () => { const component = renderer .create() .toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with brief', () => { const component = renderer .create( ) .toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with security', () => { const component = renderer .create() .toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with visible', () => { const component = renderer .create() .toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with text slot', () => { const component = renderer .create( testtest ) .toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with ReactNode slot', () => { const component = renderer .create( ) .toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with a view', () => { const component = renderer.create().toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with error', () => { const component = renderer .create() .toJSON(); expect(component).toMatchSnapshot(); }); it('renders correctly captcha with custom countdown number', () => { const component = renderer .create() .toJSON(); expect(component).toMatchSnapshot(); }); it('test show event', () => { const mockCallBack = jest.fn(); const component = shallow( ); component.setProps({ isVisible: true }); expect(mockCallBack.mock.calls.length).toEqual(1); }); it('test dismiss event', () => { const mockCallBack = jest.fn(); const component = shallow( ); component.setProps({ isVisible: false }); expect(mockCallBack.mock.calls.length).toEqual(1); }); it('test close event', () => { const mockCallBack = jest.fn(); const component = shallow( ); component .findWhere((n: any) => { return n.type() === TouchableOpacity && n.props().style.zIndex === 1301; }) .simulate('press'); expect(mockCallBack.mock.calls.length).toEqual(1); }); it('test send event', () => { const mockCallBack = jest.fn(); const component = shallow( ); expect(component.find('MDCountdown')).toHaveLength(1); component .findWhere((n: any) => { return n.type() === Text && n.text() === '发送验证码'; }) .simulate('press'); expect(mockCallBack.mock.calls.length).toEqual(1); }); it('test submit event', () => { const mockCallBack = jest.fn(); const component = shallow( ); expect(component.find('MDCodebox')).toHaveLength(1); component.find('MDCodebox').simulate('changeText', '1234'); expect(mockCallBack.mock.calls.length).toEqual(1); expect(mockCallBack.mock.calls[0][1]).toEqual('1234'); }); it('test default countdown', () => { const component = renderer.create().toJSON(); expect(component).toMatchSnapshot(); }); it('test countdown number for countdown', () => { const mockCallBack = jest.fn(); const component = shallow( ); component .findWhere((n: any) => { return n.type() === Text && n.text() === '发送验证码'; }) .simulate('press'); expect(mockCallBack.mock.calls.length).toEqual(1); });