<commit_before>import React from 'react';
import { mount } from 'enzyme';
import omit from 'lodash/omit';
import ZentForm from 'form';
import Option from 'select';

describe('GetControlGroup and Component_Fields', () => {
  const { Form, createForm, Field, getControlGroup, unknownProps } = ZentForm;
  const FormCreated = createForm()(Form);
  const DivComponent = props => {
    const passableProps = omit(props, unknownProps);
    return <div {...passableProps} />;
  };
  const context = mount(
    <FormCreated>
      <Field name="bar" component={DivComponent} />
    </FormCreated>
  )
    .find(Field)
    .getNode().context;

  it('will render default structure with example usage(as component prop of Field)', () => {
    class Input extends React.Component {
      render() {
        const passableProps = omit(this.props, unknownProps);
        return <input type="text" {...passableProps} />;
      }
    }
    const addtionInput = getControlGroup(Input);
    const wrapper = mount(
      <Field name="foo" ref="field" component={addtionInput} />,
      { context }
    );
    /**
     * .zent-form__control-group
     *   label.zent-form__control-label
     *   .zent-form__controls
     *     Control(component)
     */
    expect(wrapper.find('.zent-form__control-group').length).toBe(1);
    expect(wrapper.find('.zent-form__control-label').length).toBe(1);
    expect(wrapper.find('.zent-form__controls').length).toBe(1);
    expect(wrapper.find('input').length).toBe(1);
    expect(
      wrapper
        .get(0)
        .getWrappedComponent()
        .getControlInstance() instanceof Input
    ).toBe(true);
  });

  it('will render without ref when the wrapped component is functionial', () => {
    function Input(props) {
      const passableProps = omit(props, unknownProps);
      return <input {...passableProps} />;
    }
    const addtionInput = getControlGroup(Input);
    const wrapper = mount(
      <Field name="foo" ref="field" component={addtionInput} />,
      { context }
    );
    expect(
      wrapper
        .get(0)
        .getWrappedComponent()
        .getControlInstance() instanceof Input
    ).to.equal(undefined);
  });

  it('ControlGroup have three render switch: required, helpDesc, notice and showError', () => {
    const Input = props => {
      const passableProps = omit(props, unknownProps);
      return <input type="text" {...passableProps} />;
    };
    const addtionInput = getControlGroup(Input);
    const wrapper = mount(
      <Field
        name="foo"<commit_msg>fix check method<commit_after>import React from 'react';
import { mount } from 'enzyme';
import omit from 'lodash/omit';
import ZentForm from 'form';
import Option from 'select';

describe('GetControlGroup and Component_Fields', () => {
  const { Form, createForm, Field, getControlGroup, unknownProps } = ZentForm;
  const FormCreated = createForm()(Form);
  const DivComponent = props => {
    const passableProps = omit(props, unknownProps);
    return <div {...passableProps} />;
  };
  const context = mount(
    <FormCreated>
      <Field name="bar" component={DivComponent} />
    </FormCreated>
  )
    .find(Field)
    .getNode().context;

  it('will render default structure with example usage(as component prop of Field)', () => {
    class Input extends React.Component {
      render() {
        const passableProps = omit(this.props, unknownProps);
        return <input type="text" {...passableProps} />;
      }
    }
    const addtionInput = getControlGroup(Input);
    const wrapper = mount(
      <Field name="foo" ref="field" component={addtionInput} />,
      { context }
    );
    /**
     * .zent-form__control-group
     *   label.zent-form__control-label
     *   .zent-form__controls
     *     Control(component)
     */
    expect(wrapper.find('.zent-form__control-group').length).toBe(1);
    expect(wrapper.find('.zent-form__control-label').length).toBe(1);
    expect(wrapper.find('.zent-form__controls').length).toBe(1);
    expect(wrapper.find('input').length).toBe(1);
    expect(
      wrapper
        .get(0)
        .getWrappedComponent()
        .getControlInstance() instanceof Input
    ).toBe(true);
  });

  it('will render without ref when the wrapped component is functionial', () => {
    function Input(props) {
      const passableProps = omit(props, unknownProps);
      return <input {...passableProps} />;
    }
    const addtionInput = getControlGroup(Input);
    const wrapper = mount(
      <Field name="foo" ref="field" component={addtionInput} />,
      { context }
    );
    expect(
      wrapper
        .get(0)
        .getWrappedComponent()
        .getControlInstance()
    ).toBe(undefined);
  });

  it('ControlGroup have three render switch: required, helpDesc, notice and showError', () => {
    const Input = props => {
      const passableProps = omit(props, unknownProps);
      return <input type="text" {...passableProps} />;
    };
    const addtionInput = getControlGroup(Input);
    const wrapper = mount(
      <Field
        name="foo"
{'fraction_non_alphanumeric': 0.14067460317460317, 'fraction_numerical': 0.002380952380952381, 'mean_word_length': 2.9944532488114106, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 33, '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': '5043713', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1446, 'n_words': 341}