<commit_before>import React from 'react';
import { shallow, mount, render } from 'enzyme';
import Form from './form';

test('Should render by default a <form>', () => {
  const component = shallow(
    <Form>
      <div>dummy</div>
    </Form>
  );
  expect(component.find('form').length).toBe(1);
});

test('Should not render a <form> if useFormTag is false', () => {
  const component = shallow(
    <Form useFormTag={false}>
      <div>dummy</div>
    </Form>
  );
  expect(component.find('form').length).toBe(0);
});<commit_msg>added tests for Form value changes<commit_after>import React from 'react'
import { shallow, mount, render } from 'enzyme'
import Form from './form'
import Field from './field'

class DummyInput extends React.Component {
  render() {
    return (
      <input
        value={this.props.value || ''}
        onChange={(e) => this.props.onChange(e.target.value)}
      >
      </input>
    )
  }
}

test('Should render by default a <form>', () => {
  const component = shallow(
    <Form>
      <div>dummy</div>
    </Form>
  );
  expect(component.find('form').length).toBe(1);
});

test('Should not render a <form> if useFormTag is false', () => {
  const component = shallow(
    <Form useFormTag={false}>
      <div>dummy</div>
    </Form>
  );
  expect(component.find('form').length).toBe(0);
});

test('onChange should dispatch on changes', () => {
  let calls;
  const mockFn = jest.fn();
  const component = mount(
    <Form
      onChange={mockFn}
    >
      <Field fieldName="foo" type={DummyInput} />
    </Form>
  );

  component
    .find('input')
    .simulate('change', {target: {value: 'foobar'}})
  calls = mockFn.mock.calls[0]
  expect(mockFn.mock.calls[0][0]).toEqual({foo: 'foobar'})

  component
    .find('input')
    .simulate('change', {target: {value: 'barfoo'}})
  calls = mockFn.mock.calls[0]
  expect(calls[calls.length - 1]).toEqual({foo: 'barfoo'})


  component.find('Form').get(0).onValueChange('bar', 'test')
  calls = mockFn.mock.calls[0]
  expect(calls[calls.length - 1]).toEqual({bar: 'test', foo: 'barfoo'})
})
{'fraction_non_alphanumeric': 0.18978805394990367, 'fraction_numerical': 0.005780346820809248, 'mean_word_length': 3.4285714285714284, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 34, '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': '3778596', 'n_tokens_mistral': 699, 'n_tokens_neox': 706, 'n_words': 157}