import React from 'react';
import { assert } from 'chai';
import { createShallow, getClasses, createMount } from '../test-utils';
import MenuItem from '../MenuItem';
import Input from '../Input';
import Select from './Select';

describe('<Select />', () => {
  let shallow;
  let classes;
  let mount;
  const defaultProps = {
    input: <Input />,
    children: [<MenuItem value="1">1</MenuItem>, <MenuItem value="2">2</MenuItem>],
  };

  before(() => {
    shallow = createShallow({ dive: true });
    classes = getClasses(<Select {...defaultProps} />);
    mount = createMount();
  });

  after(() => {
    mount.cleanUp();
  });

  it('should render a correct top element', () => {
    const wrapper = shallow(<Select {...defaultProps} />);
    assert.strictEqual(wrapper.type(), Input);
  });

  it('should provide the classes to the input component', () => {
    const wrapper = shallow(<Select {...defaultProps} />);
    assert.deepEqual(wrapper.props().inputProps.classes, classes);
  });

  describe('prop: inputProps', () => {
    it('should be able to provide a custom classes property', () => {
      const wrapper = shallow(
        <Select
          {...defaultProps}
          inputProps={{
            classes: { root: 'root' },
          }}
        />,
      );
      assert.deepEqual(wrapper.props().inputProps.classes, {
        ...classes,
        root: `${classes.root} root`,
      });
    });
  });

  it('should be able to mount the component', () => {
    const wrapper = mount(
      <Select {...defaultProps} value={10}>
        <MenuItem value="">
          <em>None</em>
        </MenuItem>
        <MenuItem value={10}>Ten</MenuItem>
        <MenuItem value={20}>Twenty</MenuItem>
        <MenuItem value={30}>Thirty</MenuItem>
      </Select>,
    );
    assert.strictEqual(wrapper.find('input').props().value, 10);
  });
});

@@ -219,16 +219,45 @@
 Select';
+%0Aimport %7B spy %7D from 'sinon';
 %0A%0Adescri
@@ -1876,12 +1876,537 @@
 ;%0A  %7D);%0A
+  describe('prop: onChange', () =%3E %7B%0A    it('should get selected element from arguments', () =%3E %7B%0A      const onChangeHandler = spy();%0A      const wrapper = mount(%3CSelect onChange=%7BonChangeHandler%7D %7B...defaultProps%7D value=%7B'1'%7D /%3E);%0A      wrapper.find('%5Brole=%22button%22%5D').simulate('click');%0A      wrapper%0A        .find(MenuItem)%0A        .at(1)%0A        .simulate('click');%0A      const selected = onChangeHandler.args%5B0%5D%5B1%5D;%0A      assert.strictEqual(React.isValidElement(selected), true, 'should b be a element');%0A    %7D);%0A  %7D);%0A
 %7D);%0A

Test if child passed to onChange handler (#12852)