<commit_before>/**
 * @jsx React.DOM
 */
'use strict';

var assert            = require('assert');
var React             = require('react');
var merge             = require('react/lib/merge');
var cloneWithProps    = require('react/lib/cloneWithProps');
var ReactTestUtils    = require('react/lib/ReactTestUtils');
var sinon             = require('sinon');
var Value             = require('../Value');
var Field             = require('../Field');
var {Scalar}          = require('../schema');
var ValidationResult  = require('../ValidationResult');

describe('React Forms', () => {

  describe('<Field /> component', () => {

    var onUpdate;
    var component;

    beforeEach(() => {
      onUpdate = sinon.spy();
    });

    function renderComponent(props) {
      props = props || {};
      var value = Value(
        props.schema || <Scalar />,
        props.value || 'value',
        props.externalValidation,
        onUpdate
      );
      var field = Field(merge(props, {value}));

      component = ReactTestUtils.renderIntoDocument(field);
      return component;
    }

    function getInput(component) {
    }

    it('reacts on onChange event', () => {
      renderComponent();
      var input = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
      input.getDOMNode().value = 'newvalue';
      ReactTestUtils.Simulate.change(input);
      assert.strictEqual(onUpdate.callCount, 1);
      var updated = onUpdate.firstCall.args[0];
      assert.deepEqual(updated.value, 'newvalue');
    });

    describe('input rendering', () => {

      it('renders into <input /> by default', () => {
        renderComponent({
          value: 42
        });
        var input = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
        assert.strictEqual(input.getDOMNode().value, '42');
      });

      it('renders into component injected via schema', () => {
        renderComponent({
          schema: <Scalar input={<textarea />} />,
          value: 42
        });
        var input = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'textarea');
        assert.strictEqual(input.getDOMNode().value, '42');
      });

      it('renders into component injected via props', () => {
        renderComponent({<commit_msg>Field: add test case for onBlur<commit_after>/**
 * @jsx React.DOM
 */
'use strict';

var assert            = require('assert');
var React             = require('react');
var merge             = require('react/lib/merge');
var cloneWithProps    = require('react/lib/cloneWithProps');
var ReactTestUtils    = require('react/lib/ReactTestUtils');
var sinon             = require('sinon');
var Value             = require('../Value');
var Field             = require('../Field');
var {Scalar}          = require('../schema');
var ValidationResult  = require('../ValidationResult');

describe('React Forms', () => {

  describe('<Field /> component', () => {

    var onUpdate;
    var component;

    beforeEach(() => {
      onUpdate = sinon.spy();
    });

    function renderComponent(props) {
      props = props || {};
      var value = Value(
        props.schema || <Scalar />,
        props.value || 'value',
        props.externalValidation,
        onUpdate
      );
      var field = Field(merge(props, {value}));

      component = ReactTestUtils.renderIntoDocument(field);
      return component;
    }

    function getInput(component) {
    }

    it('reacts on onChange event', () => {
      renderComponent();
      var input = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
      input.getDOMNode().value = 'newvalue';
      ReactTestUtils.Simulate.change(input);
      assert.strictEqual(onUpdate.callCount, 1);
      var updated = onUpdate.firstCall.args[0];
      assert.deepEqual(updated.value, 'newvalue');
    });

    it('reacts on onBlur event', () => {
      renderComponent();
      var input = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
      ReactTestUtils.Simulate.blur(input);
      assert.strictEqual(onUpdate.callCount, 1);
      var updated = onUpdate.firstCall.args[0];
      assert.ok(updated.isDirty);
    });

    describe('input rendering', () => {

      it('renders into <input /> by default', () => {
        renderComponent({
          value: 42
        });
        var input = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
        assert.strictEqual(input.getDOMNode().value, '42');
      });

      it('renders into component injected via schema', () => {
        renderComponent({
          schema: <Scalar input={<textarea />} />,
          value: 42
        });
        var input = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'textarea');
        assert.strictEqual(input.getDOMNode().value, '42');
      });

      it('renders into component injected via props', () => {
        renderComponent({
{'fraction_non_alphanumeric': 0.14947927302430059, 'fraction_numerical': 0.004492546457014498, 'mean_word_length': 2.601470588235294, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 30, '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': '4863362', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1327, 'n_words': 278}