|
| 1 | +import { mount } from 'enzyme' |
| 2 | +import React from 'react' |
| 3 | + |
| 4 | +import { sleep } from './util' |
| 5 | + |
| 6 | +import Input from '../src' |
| 7 | + |
| 8 | +describe('src/index', () => { |
| 9 | + describe('should render properly', () => { |
| 10 | + let wrapper |
| 11 | + it('should render basicly', () => { |
| 12 | + wrapper = mount(<RenderInput />) |
| 13 | + expect(wrapper.find('.or-input').length).toBe(1) |
| 14 | + expect(wrapper.find('.or-input input').prop('placeholder')).toBe('') |
| 15 | + expect(wrapper.find('.or-input input').prop('value')).toBe('') |
| 16 | + expect(wrapper.find('.or-input .or-clear-icon').length).toBe(1) |
| 17 | + }) |
| 18 | + |
| 19 | + it('should render basicly #placeholder', () => { |
| 20 | + wrapper = mount(<RenderInput placeholder="name" />) |
| 21 | + expect(wrapper.find('.or-input').length).toBe(1) |
| 22 | + expect(wrapper.find('.or-input input[placeholder="name"]').length).toBe(1) |
| 23 | + expect(wrapper.find('.or-input input').prop('value')).toBe('') |
| 24 | + }) |
| 25 | + }) |
| 26 | + |
| 27 | + describe('simulate events', async () => { |
| 28 | + let wrapper |
| 29 | + it('onchange event', async () => { |
| 30 | + wrapper = mount(<RenderInput />) |
| 31 | + const input = wrapper.find('.or-input input') |
| 32 | + input.instance().value = 'yuki' |
| 33 | + input.simulate('change') |
| 34 | + // input.simulate('focus'); |
| 35 | + // input.simulate('change', { target: { value: 'Changed' } }); |
| 36 | + // input.simulate('keyDown', { |
| 37 | + // which: 72, |
| 38 | + // target: { |
| 39 | + // blur() { |
| 40 | + // // Needed since <EditableText /> calls target.blur() |
| 41 | + // input.simulate('blur'); |
| 42 | + // }, |
| 43 | + // }, |
| 44 | + // }) |
| 45 | + // await sleep(500) |
| 46 | + // expect(input.props().value).toBe('Hello'); |
| 47 | + // input.simulate('change', { target: { value: 'yuki' } }) |
| 48 | + // expect(wrapper.find('input').prop('value')).toBe('yuki') |
| 49 | + |
| 50 | + expect(input.value).toBe('yuki') |
| 51 | + }) |
| 52 | + }) |
| 53 | +}) |
| 54 | + |
| 55 | +interface Props { |
| 56 | + numericInput?: boolean |
| 57 | + maxlength?: number |
| 58 | + placeholder?: string |
| 59 | +} |
| 60 | + |
| 61 | +class RenderInput extends React.Component<Props, {}> { |
| 62 | + state = { |
| 63 | + name: '' |
| 64 | + } |
| 65 | + |
| 66 | + render() { |
| 67 | + return ( |
| 68 | + <div> |
| 69 | + <Input |
| 70 | + value={this.state.name} |
| 71 | + onChange={this.handleChange} |
| 72 | + {...this.props} |
| 73 | + /> |
| 74 | + </div> |
| 75 | + ) |
| 76 | + } |
| 77 | + |
| 78 | + handleChange = value => { |
| 79 | + this.setState({ |
| 80 | + name: value |
| 81 | + }) |
| 82 | + } |
| 83 | +} |
0 commit comments