@@ -10,7 +10,8 @@ const form = generateSchemaSingleField(
1010 'input' ,
1111 'color' ,
1212 'Pick a color' ,
13- ''
13+ '' ,
14+ { }
1415)
1516
1617const props = generatePropsSingleField ( form )
@@ -30,9 +31,21 @@ describe('FieldColor', () => {
3031 expect ( formWrapper . find ( 'input[type=color]' ) . exists ( ) ) . toBe ( true )
3132 } )
3233
34+ it ( 'Should render correctly, with input' , async ( ) => {
35+ config . global . components = { FieldColor }
36+
37+ const schema = { ...form . schema }
38+ schema . fields [ 0 ] . withInput = true
39+ const formWrapper = mountFormGenerator ( schema , form . model )
40+
41+ expect ( formWrapper . findComponent ( FieldColor ) . exists ( ) ) . toBe ( true )
42+ expect ( formWrapper . find ( 'input[type=color]' ) . exists ( ) ) . toBe ( true )
43+ expect ( formWrapper . find ( 'input[type=text]' ) . exists ( ) ) . toBe ( true )
44+ } )
45+
3346 it ( 'Should emit onInput event' , async ( ) => {
3447 const wrapper = mount ( FieldColor , { props } )
35- await wrapper . find ( 'input[type=color]' ) . trigger ( 'change ' )
48+ await wrapper . find ( 'input[type=color]' ) . trigger ( 'input ' )
3649 expect ( wrapper . emitted ( ) ) . toHaveProperty ( 'onInput' )
3750 } )
3851
@@ -47,4 +60,30 @@ describe('FieldColor', () => {
4760 expect ( formWrapper . vm . model . colorModel ) . toBe ( '#efefef' )
4861 } )
4962
63+ it ( 'Should update model value and sync values' , async ( ) => {
64+ config . global . components = { FieldColor }
65+
66+ const schema = { ...form . schema }
67+ schema . fields [ 0 ] . withInput = true
68+ const formWrapper = mountFormGenerator ( schema , form . model )
69+
70+ const wrapper = formWrapper . findComponent ( FieldColor )
71+ wrapper . find ( 'input[type=text]' ) . setValue ( '#f00000' )
72+ expect ( wrapper . emitted ( ) ) . toHaveProperty ( 'onInput' , [ [ '#f00000' ] ] )
73+ expect ( formWrapper . vm . model . colorModel ) . toBe ( '#f00000' )
74+ // Wait for the DOM to update.
75+ await wrapper . vm . $nextTick ( )
76+ expect ( wrapper . find ( 'input[type=color' ) . attributes ( ) . value ) . toBe ( '#f00000' )
77+
78+ // Clear emitted events for next interaction test.
79+ wrapper . emitted ( ) . onInput = [ ]
80+
81+ wrapper . find ( 'input[type=color]' ) . setValue ( '#ff0000' )
82+ expect ( wrapper . emitted ( ) ) . toHaveProperty ( 'onInput' , [ [ '#ff0000' ] ] )
83+ expect ( formWrapper . vm . model . colorModel ) . toBe ( '#ff0000' )
84+ // Wait for the DOM to update.
85+ await wrapper . vm . $nextTick ( )
86+ expect ( wrapper . find ( 'input[type=text]' ) . attributes ( ) . value ) . toBe ( '#ff0000' )
87+ } )
88+
5089} )
0 commit comments