<commit_before>/* eslint-disable no-unused-expressions, max-len, func-names */
import React from 'react';
import { expect } from 'chai';
import sinon, { stub } from 'sinon';
import { shallow } from 'enzyme';

import Tweet from './../examples/create-proptype/Tweet';
import Card from './../examples/create-proptype/Card';
import InvalidCallbackUsage from './../examples/create-proptype/InvalidCallbackUsage';
import InvalidMessageUsage from './../examples/create-proptype/InvalidMessageUsage';

describe('createPropType', () => {
  describe('<Tweet />', () => {
    it('should have prop(s): `text`', () => {
      const wrapper = shallow(
        <Tweet text={'Dummy tweet text'} />
      );

      expect(wrapper.props().text).to.be.defined;
    });

    it('should require `text` prop to be supplied',
    sinon.test(function () {
      const errorStub = this.stub(console, 'error');
      shallow(<Tweet />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `text` is marked as required in `Tweet`, but its value is `undefined`.\n    in Tweet'
      )).to.equal(true);

      shallow(<Tweet text={null} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `text` is marked as required in `Tweet`, but its value is `null`.\n    in Tweet'
      )).to.equal(true);
    }));

    it('should validate `text` prop to be of type string and less than 140 characters',
    sinon.test(function () {
      const errorStub = this.stub(console, 'error');
      shallow(
        <div>
          <Tweet text={42} />
          <Tweet text={'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfsadfasdfsadfasdfasdfasdfsadfsadfadfasdfasdfasdfasdfasdfsadfasdfasdfasdfsadfasfasfasfasdfasfasdfsafasf'} />
        </div>
      );

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: Invalid prop `text` supplied to `Tweet`. Validation failed.\n    in Tweet'
      )).to.equal(true);
    }));
  });

  describe('<Card />', () => {
    it('should have prop(s): `suit` & `value`', () => {
      const wrapper = shallow(
        <Card suit={'spades'} value={8} />
      );

      expect(wrapper.props().suit).to.be.defined;
      expect(wrapper.props().value).to.be.defined;
    });

    it('should require props `suit` & `value` to be supplied',
    sinon.test(function () {
      const errorStub = this.stub(console, 'error');
      shallow(<Card value={8} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `suit` is marked as required in `Card`, but its value is `undefined`.\n    in Card'
      )).to.equal(true);

      shallow(<Card suit={null} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `suit` is marked as required in `Card`, but its value is `null`.\n    in Card'
      )).to.equal(true);

      shallow(<Card suit={'spades'} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `value` is marked as required in `Card`, but its value is `undefined`.\n    in Card'
      )).to.equal(true);

      shallow(<Card value={null} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `value` is marked as required in `Card`, but its value is `null`.\n    in Card'
      )).to.equal(true);
    }));
  });

  describe('<InvalidCallbackUsage />', () => {
    it('should notify developer of incorrect usage of `callback` parameter',
    sinon.test(function () {
      const errorStub = this.stub(console, 'error');<commit_msg>Add spec for Card `suit` prop validation<commit_after>/* eslint-disable no-unused-expressions, max-len, func-names */
import React from 'react';
import { expect } from 'chai';
import sinon, { stub } from 'sinon';
import { shallow } from 'enzyme';

import Tweet from './../examples/create-proptype/Tweet';
import Card from './../examples/create-proptype/Card';
import InvalidCallbackUsage from './../examples/create-proptype/InvalidCallbackUsage';
import InvalidMessageUsage from './../examples/create-proptype/InvalidMessageUsage';

describe('createPropType', () => {
  describe('<Tweet />', () => {
    it('should have prop(s): `text`', () => {
      const wrapper = shallow(
        <Tweet text={'Dummy tweet text'} />
      );

      expect(wrapper.props().text).to.be.defined;
    });

    it('should require `text` prop to be supplied',
    sinon.test(function () {
      const errorStub = this.stub(console, 'error');
      shallow(<Tweet />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `text` is marked as required in `Tweet`, but its value is `undefined`.\n    in Tweet'
      )).to.equal(true);

      shallow(<Tweet text={null} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `text` is marked as required in `Tweet`, but its value is `null`.\n    in Tweet'
      )).to.equal(true);
    }));

    it('should validate `text` prop to be of type string and less than 140 characters',
    sinon.test(function () {
      const errorStub = this.stub(console, 'error');
      shallow(
        <div>
          <Tweet text={42} />
          <Tweet text={'asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfsadfasdfsadfasdfasdfasdfsadfsadfadfasdfasdfasdfasdfasdfsadfasdfasdfasdfsadfasfasfasfasdfasfasdfsafasf'} />
        </div>
      );

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: Invalid prop `text` supplied to `Tweet`. Validation failed.\n    in Tweet'
      )).to.equal(true);
    }));
  });

  describe('<Card />', () => {
    it('should have prop(s): `suit` & `value`', () => {
      const wrapper = shallow(
        <Card suit={'spades'} value={8} />
      );

      expect(wrapper.props().suit).to.be.defined;
      expect(wrapper.props().value).to.be.defined;
    });

    it('should require props `suit` & `value` to be supplied',
    sinon.test(function () {
      const errorStub = this.stub(console, 'error');
      shallow(<Card value={8} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `suit` is marked as required in `Card`, but its value is `undefined`.\n    in Card'
      )).to.equal(true);

      shallow(<Card suit={null} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `suit` is marked as required in `Card`, but its value is `null`.\n    in Card'
      )).to.equal(true);

      shallow(<Card suit={'spades'} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `value` is marked as required in `Card`, but its value is `undefined`.\n    in Card'
      )).to.equal(true);

      shallow(<Card value={null} />);

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: The `value` is marked as required in `Card`, but its value is `null`.\n    in Card'
      )).to.equal(true);
    }));

    it('should validate `suit` prop to be `spades`, `hearts`, `diamonds`, or `clubs`.',
    sinon.test(function () {
      const errorStub = this.stub(console, 'error');
      shallow(
        <div>
          <Card suit={'invalid string'} />
          <Card suit={24} />
          <Card suit={[]} />
        </div>
      );

      expect(errorStub.calledWithExactly(
        'Warning: Failed prop type: Invalid prop `suit`: must be `spades`, `hearts`, `diamonds`, or `clubs`.\n    in Card'
      )).to.equal(true);
    }));
  });

  describe('<InvalidCallbackUsage />', () => {
    it('should notify developer of incorrect usage of `callback` parameter',
    sinon.test(function () {
      const errorStub = this.stub(console, 'error');
{'fraction_non_alphanumeric': 0.15576772168454095, 'fraction_numerical': 0.00209259743656814, 'mean_word_length': 2.970404984423676, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 50, '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': '4413193', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2380, 'n_words': 619}