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

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

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

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

    var onUpdate;
    var _onUpdate;
    var component;

    beforeEach(() => {
      onUpdate = sinon.spy();
      _onUpdate = function(value) {
        component.setProps({value});
        onUpdate.apply(this, arguments);
      }
    });

    function renderComponent(props) {
      props = props || {};
      var root = () => value;
      var value = Value.create(
        props.schema || Scalar(),
        props.value || 'value',
        _onUpdate,
        root
      );
      var field = <Field {...props} value={value} />;

      component = ReactTestUtils.renderIntoDocument(field);
      return 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');
      //assert.ok(updated.isDirty);
    });

    it('reacts on onBlur event', () => {
      renderComponent();
      assert.ok(!component.props.value.isDirty);
      var input = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
      ReactTestUtils.Simulate.blur(input);
      assert.strictEqual(onUpdate.callCount, 1);
      assert.ok(component.props.value.isDirty);
    });

    describe('input rendering', () => {<commit_msg><Field />: test cases for assigning className<commit_after>/**
 * @jsx React.DOM
 */
'use strict';

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

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

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

    var onUpdate;
    var _onUpdate;
    var component;

    beforeEach(() => {
      onUpdate = sinon.spy();
      _onUpdate = function(value) {
        component.setProps({value});
        onUpdate.apply(this, arguments);
      }
    });

    function renderComponent(props) {
      props = props || {};
      var root = () => value;
      var value = Value.create(
        props.schema || Scalar(),
        props.value || 'value',
        _onUpdate,
        root
      );
      var field = <Field {...props} value={value} />;

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

    it('sets .rf-Field className to DOM element', function() {
      var field = renderComponent();
      assert.ok(field.getDOMNode().classList.contains('rf-Field'));
    });

    it('transfers className prop to DOM element', function() {
      var field = renderComponent({className: 'className'});
      assert.ok(field.getDOMNode().classList.contains('className'));
    });

    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');
      //assert.ok(updated.isDirty);
    });

    it('reacts on onBlur event', () => {
      renderComponent();
      assert.ok(!component.props.value.isDirty);
      var input = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
      ReactTestUtils.Simulate.blur(input);
      assert.strictEqual(onUpdate.callCount, 1);
      assert.ok(component.props.value.isDirty);
    });

    describe('input rendering', () => {
{'fraction_non_alphanumeric': 0.15568312284730196, 'fraction_numerical': 0.0013777267508610792, 'mean_word_length': 2.697792869269949, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 22, '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': '3367064', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1227, 'n_words': 244}