1
1
import { expect } from "chai" ;
2
- import { createVueField , trigger } from "../util" ;
2
+ import { createVueField , trigger , checkAttribute } from "../util" ;
3
3
4
4
import Vue from "vue" ;
5
5
import FieldCleave from "src/fields/fieldCleave.vue" ;
@@ -19,8 +19,9 @@ describe("fieldCleave.vue", function() {
19
19
type : "masked" ,
20
20
label : "Phone" ,
21
21
model : "phone" ,
22
+ autocomplete : "off" ,
23
+ placeholder : "" ,
22
24
readonly : false ,
23
- placeholder : "Field placeholder" ,
24
25
cleaveOptions : {
25
26
phone : true ,
26
27
phoneRegionCode : "HU" ,
@@ -41,40 +42,29 @@ describe("fieldCleave.vue", function() {
41
42
expect ( input ) . to . be . defined ;
42
43
expect ( input . type ) . to . be . equal ( "text" ) ;
43
44
expect ( input . classList . contains ( "form-control" ) ) . to . be . true ;
44
- expect ( input . placeholder ) . to . be . equal ( schema . placeholder ) ;
45
- expect ( input . readOnly ) . to . be . false ;
46
- expect ( input . disabled ) . to . be . false ;
47
45
} ) ;
48
46
49
47
it ( "should contain the value" , ( done ) => {
50
48
vm . $nextTick ( ( ) => {
51
- expect ( input . value ) . to . be . equal ( "30 123 4567" ) ;
49
+ expect ( input . value ) . to . be . equal ( "30 123 4567" ) ;
52
50
done ( ) ;
53
51
} ) ;
54
52
} ) ;
55
53
56
- it ( "should set readOnly" , ( done ) => {
57
- schema . readonly = true ;
58
- vm . $nextTick ( ( ) => {
59
- expect ( input . readOnly ) . to . be . true ;
60
- schema . readonly = false ;
61
- done ( ) ;
62
- } ) ;
63
- } ) ;
54
+ describe ( "check optional attribute" , ( ) => {
55
+ let attributes = [ "autocomplete" , "disabled" , "readonly" ] ;
64
56
65
- it ( "should set disabled" , ( done ) => {
66
- field . disabled = true ;
67
- vm . $nextTick ( ( ) => {
68
- expect ( input . disabled ) . to . be . true ;
69
- field . disabled = false ;
70
- done ( ) ;
57
+ attributes . forEach ( function ( name ) {
58
+ it ( "should set " + name , function ( done ) {
59
+ checkAttribute ( name , vm , input , field , schema , done ) ;
60
+ } ) ;
71
61
} ) ;
72
62
} ) ;
73
63
74
64
it ( "input value should be the model value after changed" , ( done ) => {
75
65
model . phone = "70 555 4433" ;
76
66
vm . $nextTick ( ( ) => {
77
- expect ( input . value ) . to . be . equal ( "70 555 4433" ) ;
67
+ expect ( input . value ) . to . be . equal ( "70 555 4433" ) ;
78
68
done ( ) ;
79
69
} ) ;
80
70
@@ -85,23 +75,23 @@ describe("fieldCleave.vue", function() {
85
75
trigger ( input , "input" ) ;
86
76
87
77
vm . $nextTick ( ( ) => {
88
- expect ( model . phone ) . to . be . equal ( "21 888 6655" ) ;
78
+ expect ( model . phone ) . to . be . equal ( "21 888 6655" ) ;
89
79
done ( ) ;
90
80
} ) ;
91
81
92
82
} ) ;
93
83
94
84
it ( "should be formatted data in model" , ( done ) => {
95
85
field . cleave . setRawValue ( "301234567" ) ;
96
- expect ( input . value ) . to . be . equal ( "30 123 4567" ) ;
86
+ expect ( input . value ) . to . be . equal ( "30 123 4567" ) ;
97
87
trigger ( input , "change" ) ;
98
88
99
89
vm . $nextTick ( ( ) => {
100
- expect ( model . phone ) . to . be . equal ( "30 123 4567" ) ;
90
+ expect ( model . phone ) . to . be . equal ( "30 123 4567" ) ;
101
91
done ( ) ;
102
92
} ) ;
103
93
104
- } ) ;
94
+ } ) ;
105
95
106
96
} ) ;
107
97
0 commit comments