import _slicedToArray from 'babel-runtime/helpers/slicedToArray';
/* eslint-disable react/jsx-key */
import React from 'react';
import { mount } from 'enzyme';
import Form from '..';
import Input from '../../input';
import Button from '../../button';
describe('Form.Ref', function () {
    var Test = function Test(_ref) {
        var onRef = _ref.onRef,
            show = _ref.show;

        var _Form$useForm = Form.useForm(),
            _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
            form = _Form$useForm2[0];

        var removeRef = React.useRef();
        var testRef = React.useRef();
        var listRef = React.useRef();
        return React.createElement(
            Form,
            { form: form, initialValues: { list: ['light'] } },
            show && React.createElement(
                Form.Item,
                { name: 'remove', label: 'remove' },
                React.createElement(Input, { ref: removeRef })
            ),
            React.createElement(
                Form.Item,
                { name: 'test', label: 'test' },
                React.createElement(Input, { ref: testRef })
            ),
            React.createElement(
                Form.List,
                { name: 'list' },
                function (fields) {
                    return fields.map(function (field) {
                        return React.createElement(
                            Form.Item,
                            field,
                            React.createElement(Input, { ref: listRef })
                        );
                    });
                }
            ),
            React.createElement(
                Button,
                { className: 'ref-item', onClick: function onClick() {
                        onRef(form.getFieldInstance('test'), testRef.current);
                    } },
                'Form.Item'
            ),
            React.createElement(
                Button,
                { className: 'ref-list', onClick: function onClick() {
                        onRef(form.getFieldInstance(['list', 0]), listRef.current);
                    } },
                'Form.List'
            ),
            React.createElement(
                Button,
                { className: 'ref-remove', onClick: function onClick() {
                        onRef(form.getFieldInstance('remove'), removeRef.current);
                    } },
                'Removed'
            )
        );
    };
    it('should ref work', function () {
        var onRef = jest.fn();
        var wrapper = mount(React.createElement(Test, { onRef: onRef, show: true }));
        wrapper.find('.ref-item').last().simulate('click');
        expect(onRef).toHaveBeenCalled();
        expect(onRef.mock.calls[0][0]).toBe(onRef.mock.calls[0][1]);
        onRef.mockReset();
        wrapper.find('.ref-list').last().simulate('click');
        expect(onRef).toHaveBeenCalled();
        expect(onRef.mock.calls[0][0]).toBe(onRef.mock.calls[0][1]);
        onRef.mockReset();
        wrapper.setProps({ show: false });
        wrapper.update();
        wrapper.find('.ref-remove').last().simulate('click');
        expect(onRef).toHaveBeenCalledWith(undefined, null);
    });
});