<commit_before>require('../spec_helper');
import {itPropagatesAttributes} from '../support/shared_examples';

describe('inputs', function() {
  describe('SearchInput', function() {
    let SearchInput;
    beforeEach(function() {
      SearchInput = require('../../../src/pivotal-ui-react/inputs/inputs').SearchInput;
      ReactDOM.render((<SearchInput className="foo myClass" id="bar" style={{opacity: '0.5'}}/>), root);
    });

    it('renders a form group with the search classes', function() {
      expect('.form-group').toHaveClass('form-group-search');

      expect('.form-group input').toHaveClass('form-control');

      expect('.form-group i').toHaveClass('search-icon');
    });

    describe('when a placeholder is provided', function() {
      beforeEach(function() {
        ReactDOM.render((<SearchInput placeholder="Search here..."/>), root);
      });

      it('renders the input with a placeholder', function() {
        expect('.form-group input').toHaveAttr('placeholder', 'Search here...');
      });

      it('adds an aria label with the placeholder value', function() {
        expect('.form-group input').toHaveAttr('aria-label', 'Search here...');
      });

      describe('when an aria-label is provided as well', function() {
        beforeEach(function() {
          ReactDOM.render((<SearchInput placeholder="Search here..." aria-label="Search Box" />), root);
        });

        it('uses the label as the aria-label instead of the placeholder', function() {
          expect('.form-group input').toHaveAttr('aria-label', 'Search Box');
        });
      });
    });

    itPropagatesAttributes('.form-group input', {className: 'foo', id: 'bar', style: {opacity: '0.5'}});

    describe('when event handlers are provided', function() {
      let changeSpy;
      beforeEach(function() {
        changeSpy = jasmine.createSpy('change');
        ReactDOM.render((<SearchInput onChange={changeSpy}/>), root);
      });

      it('adds the handlers to the search input', function() {
        $('input:eq(0)').simulate('change');
        expect(changeSpy).toHaveBeenCalled();
      });
    });
  });

  describe('BasicInput', function() {
    let changeSpy, BasicInput;
    const id = 'firstNameInput';
    const label = '<NAME>';
    beforeEach(function () {
      BasicInput = require('../../../src/pivotal-ui-react/inputs/inputs').BasicInput;
      changeSpy = jasmine.createSpy('change');
      ReactDOM.render(<BasicInput success {...{className: 'input-class', label, id, onChange: changeSpy}}/>, root);
    });

    it('renders an input with the label', function() {
      expect('.form-group label').toContainText('<NAME>');
    });

    it('attaches the label to the input', function() {
      expect('.form-group label').toHaveAttr('for', id);
      expect('.form-group input').toHaveAttr('id', id);
    });

    it('passes properties to the input', function() {
      $('.form-group input').simulate('change');
      expect(changeSpy).toHaveBeenCalled();
    });

    it('displays a checkmark when success prop is true', () => {
      expect('.has-success').toExist();
    });

    it('merges classnames', function() {
      expect('.form-group input').toHaveClass( 'form-control');
      expect('.form-group').toHaveClass('input-class');
    });

    describe('Validation', function() {
      it('does not show error messages when displayError is false', function() {
        expect('.error-text').not.toExist();
      });
      it('shows error messages when displayError is true', function() {
        ReactDOM.render(<BasicInput displayError {...{className: 'input-class', label, id, onChange: changeSpy}}/>, root);
        expect('.error-text').toExist();
        expect('.error-text').toHaveText(`Please enter your ${label.toLowerCase()}.`);
      });
    });<commit_msg>fix(BasicInput): Label is selected correctly in specs<commit_after>require('../spec_helper');
import {itPropagatesAttributes} from '../support/shared_examples';

describe('inputs', function() {
  describe('SearchInput', function() {
    let SearchInput;
    beforeEach(function() {
      SearchInput = require('../../../src/pivotal-ui-react/inputs/inputs').SearchInput;
      ReactDOM.render((<SearchInput className="foo myClass" id="bar" style={{opacity: '0.5'}}/>), root);
    });

    it('renders a form group with the search classes', function() {
      expect('.form-group').toHaveClass('form-group-search');

      expect('.form-group input').toHaveClass('form-control');

      expect('.form-group i').toHaveClass('search-icon');
    });

    describe('when a placeholder is provided', function() {
      beforeEach(function() {
        ReactDOM.render((<SearchInput placeholder="Search here..."/>), root);
      });

      it('renders the input with a placeholder', function() {
        expect('.form-group input').toHaveAttr('placeholder', 'Search here...');
      });

      it('adds an aria label with the placeholder value', function() {
        expect('.form-group input').toHaveAttr('aria-label', 'Search here...');
      });

      describe('when an aria-label is provided as well', function() {
        beforeEach(function() {
          ReactDOM.render((<SearchInput placeholder="Search here..." aria-label="Search Box" />), root);
        });

        it('uses the label as the aria-label instead of the placeholder', function() {
          expect('.form-group input').toHaveAttr('aria-label', 'Search Box');
        });
      });
    });

    itPropagatesAttributes('.form-group input', {className: 'foo', id: 'bar', style: {opacity: '0.5'}});

    describe('when event handlers are provided', function() {
      let changeSpy;
      beforeEach(function() {
        changeSpy = jasmine.createSpy('change');
        ReactDOM.render((<SearchInput onChange={changeSpy}/>), root);
      });

      it('adds the handlers to the search input', function() {
        $('input:eq(0)').simulate('change');
        expect(changeSpy).toHaveBeenCalled();
      });
    });
  });

  describe('BasicInput', function() {
    let changeSpy, BasicInput;
    const id = 'firstNameInput';
    const label = '<NAME>';
    beforeEach(function () {
      BasicInput = require('../../../src/pivotal-ui-react/inputs/inputs').BasicInput;
      changeSpy = jasmine.createSpy('change');
      ReactDOM.render(<BasicInput success {...{className: 'input-class', label, id, onChange: changeSpy}}/>, root);
    });

    it('renders an input with the label', function() {
      expect('.control-label').toContainText('<NAME>');
    });

    it('attaches the label to the input', function() {
      expect('.control-label').toHaveAttr('for', id);
      expect('.form-group input').toHaveAttr('id', id);
    });

    it('passes properties to the input', function() {
      $('.form-group input').simulate('change');
      expect(changeSpy).toHaveBeenCalled();
    });

    it('displays a checkmark when success prop is true', () => {
      expect('.has-success').toExist();
    });

    it('merges classnames', function() {
      expect('.form-group input').toHaveClass( 'form-control');
      expect('.form-group').toHaveClass('input-class');
    });

    describe('Validation', function() {
      it('does not show error messages when displayError is false', function() {
        expect('.error-text').not.toExist();
      });
      it('shows error messages when displayError is true', function() {
        ReactDOM.render(<BasicInput displayError {...{className: 'input-class', label, id, onChange: changeSpy}}/>, root);
        expect('.error-text').toExist();
        expect('.error-text').toHaveText(`Please enter your ${label.toLowerCase()}.`);
      });
    });
{'fraction_non_alphanumeric': 0.18448500651890481, 'fraction_numerical': 0.001303780964797914, 'mean_word_length': 3.2217941662080354, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '4818052', 'n_tokens_mistral': 2176, 'n_tokens_neox': 2150, 'n_words': 484}