@@ -10,7 +10,8 @@ const form = generateSchemaSingleField(
10
10
'input' ,
11
11
'color' ,
12
12
'Pick a color' ,
13
- ''
13
+ '' ,
14
+ { }
14
15
)
15
16
16
17
const props = generatePropsSingleField ( form )
@@ -30,9 +31,21 @@ describe('FieldColor', () => {
30
31
expect ( formWrapper . find ( 'input[type=color]' ) . exists ( ) ) . toBe ( true )
31
32
} )
32
33
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
+
33
46
it ( 'Should emit onInput event' , async ( ) => {
34
47
const wrapper = mount ( FieldColor , { props } )
35
- await wrapper . find ( 'input[type=color]' ) . trigger ( 'change ' )
48
+ await wrapper . find ( 'input[type=color]' ) . trigger ( 'input ' )
36
49
expect ( wrapper . emitted ( ) ) . toHaveProperty ( 'onInput' )
37
50
} )
38
51
@@ -47,4 +60,30 @@ describe('FieldColor', () => {
47
60
expect ( formWrapper . vm . model . colorModel ) . toBe ( '#efefef' )
48
61
} )
49
62
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
+
50
89
} )
0 commit comments