{"size": 1818, "ext": "js", "max_stars_repo_path": "test/containers/Form/Fields/selectMultipleBindTo.spec.js", "max_stars_repo_name": "aichbauer/react-form-package", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/containers/Form/Fields/selectMultipleBindTo.spec.js", "max_issues_repo_name": "aichbauer/react-form-package", "max_issues_repo_issues_event_min_datetime": "2018-10-04T08:14:52.000Z", "max_issues_repo_issues_event_max_datetime": "2020-02-16T21:55:23.000Z", "max_forks_repo_path": "test/containers/Form/Fields/selectMultipleBindTo.spec.js", "max_forks_repo_name": "aichbauer/react-form-package", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 40, "max_forks_count": null, "avg_line_length": 20.8965517241, "max_line_length": 72, "alphanum_fraction": 0.5209020902}
import React from 'react';
import renderer from 'react-test-renderer';
import Adapter from 'enzyme-adapter-react-16';
import { configure, mount } from 'enzyme';

import {
  Form,
  Field,
  Select,
} from '../../../../src';

configure({ adapter: new Adapter() });

test('Render Form with select input | bindTo', () => {
  const event = {
    target: {
      id: 'emailTemplate',
      value: 'friends',
    },
  };
  const rules = {
    type: 'select',
    min: '-1',
    max: '-1',
    required: false,
  };

  const myComponent = (
    <Form>
      <Select
        id="emailTemplate"
        bindTo={[
          'subject',
          'body',
        ]}
        bindToAlways
        bindToCallback={(value) => {
          if (value === 'friends') {
            return [
              'Friends',
              'Friends Friends',
            ];
          }

          return [
            'Boss',
            'Boss Boss',
          ];
        }}
      >
        <option disabled value="">
          --- Select an email template ---
        </option>
        <option value="friends">Friends</option>
        <option value="boss">Boss</option>
      </Select>
      <Field
        id="subject"
        type="text"
      />
      <Field
        id="body"
        type="textarea"
        rows="5"
        cols="40"
      />
    </Form>
  );

  const tree = renderer.create(myComponent).toJSON();
  const wrapper = mount(myComponent);
  let state = wrapper.state();

  expect(state.data.subject.value).toBe('');
  expect(state.data.body.value).toBe('');

  wrapper.find('select#emailTemplate').simulate('change', event, rules);
  wrapper.update();

  state = wrapper.state();

  expect(state.data.subject.value).toBe('Friends');
  expect(state.data.body.value).toBe('Friends Friends');

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