@@ -2,7 +2,8 @@ import React from 'react';
22import CodeInputField from './ReactCodeInput.js' ;
33
44const numbers = '123456' ,
5- chars = '123FE3' ;
5+ chars = '123FE3' ,
6+ placeholder = '0' ;
67
78describe ( 'CodeInputField' , ( ) => {
89 test ( 'renders without error' , ( ) => {
@@ -13,9 +14,10 @@ describe('CodeInputField', () => {
1314
1415 test ( 'renders field without any values' , ( ) => {
1516 const wrapper = shallow ( < CodeInputField /> ) ;
16-
17+
1718 expect ( wrapper . find ( 'input' ) ) . toHaveLength ( 4 ) ;
1819 expect ( wrapper . state ( ) . fields ) . toEqual ( 4 ) ;
20+ expect ( CodeInputField . defaultProps . placeholder ) . toBeUndefined ( ) ;
1921 expect ( wrapper . state ( ) . value ) . toEqual ( '' ) ;
2022 expect ( wrapper . state ( ) . type ) . toEqual ( 'text' ) ;
2123 expect ( wrapper . state ( ) . input ) . toBeInstanceOf ( Array ) ;
@@ -40,12 +42,22 @@ describe('CodeInputField', () => {
4042 }
4143 expect ( val . join ( '' ) ) . toEqual ( chars ) ;
4244 } ) ;
45+
46+ test ( `renders component with placeholder: ${ placeholder } ` , ( ) => {
47+ const wrapper = render ( < CodeInputField value = { numbers } fields = { 6 } type = "number" placeholder = { placeholder } /> ) ,
48+ val = [ ] ;
49+ for ( let i = 0 ; i < numbers . length ; i += 1 ) {
50+ val . push ( wrapper . find ( 'input' ) [ i ] . attribs . value ) ;
51+ }
52+ expect ( val . join ( '' ) ) . toEqual ( numbers ) ;
53+ } ) ;
4354
4455 test ( 'mount component with props: "fields={6}"' , ( ) => {
4556 const wrapper = mount ( < CodeInputField fields = { 6 } /> ) ;
4657 expect ( wrapper . props ( ) . fields ) . toEqual ( 6 ) ;
4758 } ) ;
4859
60+
4961 test ( 'should have 4 input felds' , ( ) => {
5062 const wrapper = shallow ( < CodeInputField /> ) ;
5163 expect ( wrapper . find ( 'input' ) ) . toHaveLength ( 4 ) ;
0 commit comments