<commit_before>import React from 'react';
import renderer from 'react-test-renderer';
import { Field, FieldArray, reduxForm } from 'redux-form';
import { createStore } from 'redux';
import { connect, Provider } from 'react-redux';

import MultiRowField from '../../../components/MultiRowField/MultiRowField';

const initialValues = {
    'mock-name': [
        {
            name: 'me',
        },
        {
            name: 'you',
        }
    ]
};

// const spy = jest.fn();
const store = createStore(() => ({
    form: {
        mockForm: {
            values: initialValues,
        }
    }
}));

let Form = ({ children, initialValues }) => children;

const _Form = connect(
    () => ({
        initialValues
    }),
    null,
)(
    reduxForm({
        form: 'mockForm',
    })(Form)
);

describe('MultiRowField component', () => {
    const requiredProps = {
        name: 'mock-name',
    };

    const wrap = el => renderer
        .create(
            <Provider store={store}>
                <_Form
                >
                    {el}
                </_Form>
            </Provider>
        );

    it('renders correctly', () => {
        const tree = wrap(
            <MultiRowField
                {...requiredProps}
            />
        ).toJSON();

        expect(tree).toMatchSnapshot();
    });

    it('renders all what was passed as a props', () => {
        const notRequiredProps = {
            hint: 'mock-hint',
            title: 'mock-title',
            placeholder: 'mock-placeholder',
        };

        const tree = wrap(
            <MultiRowField
                {...requiredProps}
                {...notRequiredProps}
            />
        ).toJSON();

        expect(tree).toMatchSnapshot();
    });

    it('calls push method when Control `Add` was clicked', () => {
        const tree = wrap(
            <MultiRowField
                {...requiredProps}
            />
        ).toJSON();

        expect(tree.children[0].children[0].children[1].props.onClick().type).toBe('@@redux-form/ARRAY_PUSH');
    });
});
<commit_msg>check if '.remove()' is calling on Control<Remove> click<commit_after>import React from 'react';
import renderer from 'react-test-renderer';
import { Field, FieldArray, reduxForm } from 'redux-form';
import { createStore } from 'redux';
import { connect, Provider } from 'react-redux';
import { mount } from 'enzyme';
import toJSON from 'enzyme-to-json';

import MultiRowField from '../../../components/MultiRowField/MultiRowField';

const initialValues = {
    'mock-name': [
        {
            name: 'me',
        },
        {
            name: 'you',
        },
    ]
};

// const spy = jest.fn();
const store = createStore(() => ({
    form: {
        mockForm: {
            values: initialValues,
        }
    }
}));

let Form = ({ children, initialValues }) => children;

const _Form = connect(
    () => ({
        initialValues
    }),
    null,
)(
    reduxForm({
        form: 'mockForm',
    })(Form)
);

const renderFakeForm = el => <Provider store={store}>
    <_Form
    >
        {el}
    </_Form>
</Provider>;

describe('MultiRowField component', () => {
    const requiredProps = {
        name: 'mock-name',
    };

    const wrap = el => renderer
        .create(
            renderFakeForm(el)
        );

    it('renders correctly', () => {
        const tree = wrap(
            <MultiRowField
                {...requiredProps}
            />
        ).toJSON();

        expect(tree).toMatchSnapshot();
    });

    it('renders all what was passed as a props', () => {
        const notRequiredProps = {
            hint: 'mock-hint',
            title: 'mock-title',
            placeholder: 'mock-placeholder',
        };

        const tree = wrap(
            <MultiRowField
                {...requiredProps}
                {...notRequiredProps}
            />
        ).toJSON();

        expect(tree).toMatchSnapshot();
    });

    it('calls `push` method when Control `Add` was clicked', () => {
        const tree = wrap(
            <MultiRowField
                {...requiredProps}
            />
        ).toJSON();

        expect(tree.children[0].children[0].children[1].props.onClick().type).toBe('@@redux-form/ARRAY_PUSH');
    });

    it('calls `remove` method when Control `Remove` was clicked', () => {
        const wrapper = mount(
            renderFakeForm(
                <MultiRowField
                    {...requiredProps}
                />
            )
        );
        const controls = [...wrapper.find('.j-control')];

        // first Control for adding, all others for removing
        expect(controls[1].props.onClick().type).toBe('@@redux-form/ARRAY_REMOVE');
    });
});

{'fraction_non_alphanumeric': 0.15420461766574878, 'fraction_numerical': 0.0014827367083245075, 'mean_word_length': 1.6768707482993197, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4821971', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1311, 'n_words': 291}