<commit_before>import React from 'react';
import { render, shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import Stepper from '../index';

describe('Stepper', () => {
  it('renders correctly', () => {
    const onChange = jest.fn();
    const wrapper = render(
      <Stepper onChange={onChange} />,
    );
    expect(toJson(wrapper)).toMatchSnapshot();
  });

  it('defaultValue', () => {
    const wrapper = shallow(
      <Stepper defaultValue={2} />,
    );
    expect(toJson(wrapper)).toMatchSnapshot();
  });

  it('receive new value', () => {
    const onChange = jest.fn();
    const wrapper = shallow(
      <Stepper onChange={onChange} />,
    );
    wrapper.setProps({ value: 10 });
  });

  it('onChange and onInputChange', () => {
    const onChange = jest.fn();
    const onInputChange = jest.fn();
    const wrapper = shallow(
      <Stepper onChange={onChange} onInputChange={onInputChange} />,
    );
    wrapper.find('input').simulate('change', { target: { value: 10 } });
    expect(onInputChange).toBeCalled();
    wrapper.find('input').simulate('blur');
    expect(onChange).toBeCalledWith(10);
    wrapper.find('.za-stepper__sub').simulate('click');
    expect(onChange).toBeCalledWith(9);
    wrapper.find('.za-stepper__plus').simulate('click');
    expect(onChange).toBeCalledWith(10);
  });
});<commit_msg>test: add conformance suite<commit_after>import React from 'react';
import { render, shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import Stepper from '../index';

describe('Stepper', () => {
  it('renders correctly', () => {
    const onChange = jest.fn();
    const wrapper = render(
      <Stepper onChange={onChange} />,
    );
    expect(toJson(wrapper)).toMatchSnapshot();
  });

  it('defaultValue', () => {
    const wrapper = shallow(
      <Stepper defaultValue={2} />,
    );
    expect(toJson(wrapper)).toMatchSnapshot();
  });

  it('disabled sub or plus click', () => {
    const onChange = jest.fn();

    const wrapper = shallow(
      <Stepper
        max={2}
        min={0}
        onChange={onChange}
      />,
    );

    wrapper.setProps({ value: 0 });
    wrapper.find('.za-stepper__sub').simulate('click');
    expect(wrapper.find('input').props().value).toBe(0);

    wrapper.setProps({ value: 2 });
    wrapper.find('.za-stepper__plus').simulate('click');
    expect(wrapper.find('input').props().value).toBe(2);
  });

  it('receive new value', () => {
    const onChange = jest.fn();
    const wrapper = shallow(
      <Stepper onChange={onChange} />,
    );
    wrapper.setProps({ value: 10 });
  });

  it('onChange and onInputChange', () => {
    const onChange = jest.fn();
    const onInputChange = jest.fn();

    const wrapper = shallow(
      <Stepper
        min={null}
        max={null}
        onChange={onChange}
        onInputChange={onInputChange}
      />,
    );

    wrapper.find('input').simulate('change', { target: { value: 10 } });
    expect(onInputChange).toBeCalled();

    wrapper.setProps({ value: 10 });
    wrapper.find('.za-stepper__sub').simulate('click');
    expect(onChange).toBeCalledWith(9);

    wrapper.find('.za-stepper__plus').simulate('click');
    expect(onChange).toBeCalledWith(10);
  });

  it('input value is NaN', () => {
    const onChange = jest.fn();
    const onInputChange = jest.fn();

    const wrapper = shallow(
      <Stepper
        min={0}
        max={20}
        value={10}
        onChange={onChange}
        onInputChange={onInputChange}
      />,
    );

    wrapper.find('input').simulate('change', { target: { value: '你好' } });
    wrapper.find('input').simulate('blur');
    expect(onChange).toBeCalledWith(10);
  });


  it('out of range', () => {
    const onChange = jest.fn();
    const onInputChange = jest.fn();
    const wrapper = shallow(
      <Stepper min={0} max={20} onChange={onChange} onInputChange={onInputChange} />,
    );

    wrapper.setProps({ value: -2 });
    wrapper.find('input').simulate('blur');
    expect(onChange).toBeCalledWith(0);

    wrapper.setProps({ value: 30 });
    wrapper.find('input').simulate('blur');
    expect(onChange).toBeCalledWith(20);
  });
});
{'fraction_non_alphanumeric': 0.18737957610789982, 'fraction_numerical': 0.010115606936416185, 'mean_word_length': 3.2034412955465585, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 27, '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': '2879011', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1294, 'n_words': 235}