@@ -27,23 +27,6 @@ describe('Select.combobox', () => {
2727 expect ( wrapper . state ( ) . inputValue ) . toBe ( '1' ) ;
2828 } ) ;
2929
30- it ( 'display correct label when value changes' , ( ) => {
31- const wrapper = mount (
32- < Select
33- combobox
34- labelInValue
35- value = { { value : '' , key : '' } }
36- optionLabelProp = "children"
37- >
38- < Option value = "1" > One</ Option >
39- < Option value = "2" > Two</ Option >
40- </ Select >
41- ) ;
42-
43- wrapper . setProps ( { value : { label : 'One' , key : '1' } } ) ;
44- expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toBe ( 'One' ) ;
45- } ) ;
46-
4730 it ( 'fire change event immediately when user inputing' , ( ) => {
4831 const handleChange = jest . fn ( ) ;
4932 const wrapper = mount (
@@ -72,4 +55,60 @@ describe('Select.combobox', () => {
7255 dropdownWrapper . find ( 'MenuItem' ) . first ( ) . simulate ( 'click' ) ;
7356 expect ( wrapper . state ( ) . inputValue ) . toBe ( '1' ) ;
7457 } ) ;
58+
59+ describe ( 'input value' , ( ) => {
60+ const createSelect = ( props ) => mount (
61+ < Select
62+ combobox
63+ optionLabelProp = "children"
64+ { ...props }
65+ >
66+ < Option value = "1" > One</ Option >
67+ < Option value = "2" > Two</ Option >
68+ </ Select >
69+ ) ;
70+
71+ describe ( 'labelInValue is false' , ( ) => {
72+ it ( 'displays correct input value for defaultValue' , ( ) => {
73+ const wrapper = createSelect ( {
74+ defaultValue : '1' ,
75+ } ) ;
76+ expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toBe ( 'One' ) ;
77+ } ) ;
78+
79+ it ( 'displays correct input value for value' , ( ) => {
80+ const wrapper = createSelect ( {
81+ value : '1' ,
82+ } ) ;
83+ expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toBe ( 'One' ) ;
84+ } ) ;
85+ } ) ;
86+
87+ describe ( 'labelInValue is true' , ( ) => {
88+ it ( 'displays correct input value for defaultValue' , ( ) => {
89+ const wrapper = createSelect ( {
90+ labelInValue : true ,
91+ defaultValue : { key : '1' , label : 'One' } ,
92+ } ) ;
93+ expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toBe ( 'One' ) ;
94+ } ) ;
95+
96+ it ( 'displays correct input value for value' , ( ) => {
97+ const wrapper = createSelect ( {
98+ labelInValue : true ,
99+ value : { key : '1' , label : 'One' } ,
100+ } ) ;
101+ expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toBe ( 'One' ) ;
102+ } ) ;
103+
104+ it ( 'displays correct input value when value changes' , ( ) => {
105+ const wrapper = createSelect ( {
106+ labelInValue : true ,
107+ value : { key : '' } ,
108+ } ) ;
109+ wrapper . setProps ( { value : { key : '1' , label : 'One' } } ) ;
110+ expect ( wrapper . find ( 'input' ) . props ( ) . value ) . toBe ( 'One' ) ;
111+ } ) ;
112+ } ) ;
113+ } ) ;
75114} ) ;
0 commit comments