|
| 1 | +'use strict' |
| 2 | + |
| 3 | +import './requestAnimationFrame' |
| 4 | + |
| 5 | +import React from 'react' |
| 6 | +import Enzyme from 'enzyme' |
| 7 | +import ReactSixteenAdapter from 'enzyme-adapter-react-16' |
| 8 | + |
| 9 | +import InputHandler from '../src/ReactInputHandler' |
| 10 | +import { createForm } from './utils' |
| 11 | + |
| 12 | +Enzyme.configure({ adapter: new ReactSixteenAdapter() }) |
| 13 | + |
| 14 | +describe('react-input-handler', () => { |
| 15 | + |
| 16 | + it('persist <select /> changes into state when no option selected', () => { |
| 17 | + const form = Enzyme.mount(createForm('select', { name: 'number' }, ( |
| 18 | + [ |
| 19 | + <option key="0" value="none">Choose a number</option>, |
| 20 | + <option key="1" value="one">One</option>, |
| 21 | + <option key="2" value="two">Two</option>, |
| 22 | + <option key="3" value="three">Three</option>, |
| 23 | + ] |
| 24 | + ))) |
| 25 | + |
| 26 | + form.find('select').simulate('change') |
| 27 | + expect(form.state('number')).toBe('none') |
| 28 | + }) |
| 29 | + |
| 30 | + it('persist <select /> changes into state when a option is selected', () => { |
| 31 | + const form = Enzyme.mount(createForm('select', { name: 'test', defaultValue: 'one' }, ( |
| 32 | + [ |
| 33 | + <option key="0" value="none">Choose a number</option>, |
| 34 | + <option key="1" value="one">One</option>, |
| 35 | + <option key="2" value="two">Two</option>, |
| 36 | + <option key="3" value="three">Three</option>, |
| 37 | + ] |
| 38 | + ))) |
| 39 | + |
| 40 | + form.find('select').simulate('change') |
| 41 | + expect(form.state('test')).toBe('one') |
| 42 | + }) |
| 43 | + |
| 44 | + it('persist <select multiple /> changes into state when multiple options are selected', () => { |
| 45 | + const form = Enzyme.mount(createForm('select', { name: 'test', multiple: true, defaultValue: ['one', 'two'] }, ( |
| 46 | + [ |
| 47 | + <option key="0" value="none">Choose a number</option>, |
| 48 | + <option key="1" value="one">One</option>, |
| 49 | + <option key="2" value="two">Two</option>, |
| 50 | + <option key="3" value="three">Three</option>, |
| 51 | + ] |
| 52 | + ))) |
| 53 | + |
| 54 | + form.find('select').simulate('change') |
| 55 | + expect(form.state('test')).toEqual(['one', 'two']) |
| 56 | + }) |
| 57 | + |
| 58 | +}) |
0 commit comments