1
- import { createVueField , trigger , checkAttribute } from "../util" ;
1
+ import { mount , createLocalVue } from "@vue/test-utils" ;
2
+ import { checkAttribute2 } from "../util" ;
2
3
3
- import Vue from "vue" ;
4
4
import FieldSelectEx from "src/fields/optional/fieldSelectEx.vue" ;
5
5
6
- Vue . component ( "FieldSelectEx" , FieldSelectEx ) ;
6
+ const localVue = createLocalVue ( ) ;
7
+ let wrapper ;
8
+ let input ;
7
9
8
- let el , vm , field ;
10
+ function createField2 ( data , methods ) {
11
+ const _wrapper = mount ( FieldSelectEx , {
12
+ localVue,
13
+ propsData : data ,
14
+ methods : methods
15
+ } ) ;
16
+
17
+ wrapper = _wrapper ;
18
+ input = wrapper . find ( "select" ) ;
9
19
10
- function createField ( test , schema = { } , model = null , disabled = false , options ) {
11
- [ el , vm , field ] = createVueField ( test , "fieldSelectEx" , schema , model , disabled , options ) ;
20
+ return _wrapper ;
12
21
}
13
22
14
- describe . skip ( "fieldSelectEx.vue" , function ( ) {
23
+ describe ( "fieldSelectEx.vue" , ( ) => {
15
24
describe ( "check template" , ( ) => {
16
25
let schema = {
17
26
type : "selectEx" ,
18
27
label : "Cities" ,
19
28
model : "city" ,
29
+ disabled : false ,
20
30
multiSelect : false ,
21
31
required : false ,
32
+ inputName : "" ,
22
33
values : [ "London" , "Paris" , "Rome" , "Berlin" ]
23
34
} ;
24
35
let model = { city : "Paris" } ;
25
- let input ;
26
36
27
37
before ( ( ) => {
28
- createField ( this , schema , model , false ) ;
29
- input = el . getElementsByTagName ( "select" ) [ 0 ] ;
38
+ createField2 ( { schema, model, disabled : false } ) ;
30
39
} ) ;
31
40
32
41
it ( "should contain a select element" , ( ) => {
33
- expect ( field ) . to . be . exist ;
34
- expect ( field . $el ) . to . be . exist ;
35
-
36
- expect ( input ) . to . be . defined ;
42
+ expect ( wrapper . exists ( ) ) . to . be . true ;
43
+ expect ( input . exists ( ) ) . to . be . true ;
37
44
} ) ;
38
45
39
46
it ( "should contain option elements" , ( ) => {
40
- let options = input . querySelectorAll ( "option" ) ;
41
- expect ( options . length ) . to . be . equal ( 4 + 1 ) ; // +1 for <non selected>
47
+ let options = input . findAll ( "option" ) ;
42
48
43
- expect ( options [ 2 ] . value ) . to . be . equal ( "Paris" ) ;
44
- expect ( options [ 2 ] . textContent ) . to . be . equal ( "Paris" ) ;
45
- expect ( options [ 2 ] . selected ) . to . be . true ;
49
+ expect ( options . length ) . to . be . equal ( 4 + 1 ) ; // +1 for <non selected>
50
+ expect ( options . at ( 2 ) . element . value ) . to . be . equal ( "Paris" ) ;
51
+ expect ( options . at ( 2 ) . text ( ) ) . to . be . equal ( "Paris" ) ;
52
+ expect ( options . at ( 2 ) . element . selected ) . to . be . true ;
46
53
} ) ;
47
54
48
55
it ( "should contain a <non selected> element" , ( ) => {
49
- let options = input . querySelectorAll ( "option" ) ;
50
- expect ( options [ 0 ] . disabled ) . to . be . false ;
51
- //expect(options[0].textContent).to.be.equal("<Not selected>");
56
+ let options = input . findAll ( "option" ) ;
57
+
58
+ expect ( options . at ( 0 ) . attributes ( ) . disabled ) . to . be . undefined ;
59
+ // expect(options.at(0).text()).to.be.equal("<Not selected>");
52
60
} ) ;
53
61
54
- it ( "should contain the value" , done => {
55
- vm . $nextTick ( ( ) => {
56
- expect ( input . value ) . to . be . equal ( "Paris" ) ;
57
- done ( ) ;
58
- } ) ;
62
+ it ( "should contain the value" , ( ) => {
63
+ expect ( input . element . value ) . to . be . equal ( "Paris" ) ;
59
64
} ) ;
60
65
61
66
describe ( "check optional attribute" , ( ) => {
62
67
let attributes = [ "disabled" , "multiSelect" , "inputName" ] ;
63
68
64
- attributes . forEach ( function ( name ) {
65
- it ( "should set " + name , function ( done ) {
66
- checkAttribute ( name , vm , input , field , schema , done ) ;
69
+ attributes . forEach ( name => {
70
+ it ( "should set " + name , ( ) => {
71
+ checkAttribute2 ( name , wrapper , schema , "select" ) ;
67
72
} ) ;
68
73
} ) ;
69
74
} ) ;
70
75
71
- it ( "input value should be the model value after changed" , done => {
76
+ it ( "input value should be the model value after changed" , ( ) => {
72
77
model . city = "Rome" ;
73
- vm . $nextTick ( ( ) => {
74
- expect ( input . value ) . to . be . equal ( "Rome" ) ;
75
- done ( ) ;
76
- } ) ;
78
+ wrapper . update ( ) ;
79
+
80
+ expect ( input . element . value ) . to . be . equal ( "Rome" ) ;
77
81
} ) ;
78
82
79
- it ( "model value should be the input value if changed" , done => {
80
- input . value = "London" ;
81
- trigger ( input , "change" ) ;
83
+ it ( "model value should be the input value if changed" , ( ) => {
84
+ input . element . value = "London" ;
85
+ input . trigger ( "change" ) ;
82
86
83
- vm . $nextTick ( ( ) => {
84
- expect ( model . city ) . to . be . equal ( "London" ) ;
85
- done ( ) ;
86
- } ) ;
87
+ expect ( model . city ) . to . be . equal ( "London" ) ;
87
88
} ) ;
88
89
89
- it ( "should not be multiple" , done => {
90
+ it . skip ( "should not be multiple" , ( ) => {
90
91
model . city = [ ] ; // For multiselect need empty array
91
92
schema . multiSelect = true ;
92
- vm . $nextTick ( ( ) => {
93
- expect ( input . multiple ) . to . be . true ;
94
- let options = input . querySelectorAll ( "option" ) ;
95
- expect ( options . length ) . to . be . equal ( 4 ) ; // no <non selected>
93
+ wrapper . update ( ) ;
96
94
97
- done ( ) ;
98
- } ) ;
95
+ expect ( input . attributes ( ) . multiple ) . to . equal ( "multiple" ) ;
96
+ let options = input . findAll ( "option" ) ;
97
+ console . log ( options . at ( 0 ) . html ( ) ) ;
98
+ console . log ( options . at ( 1 ) . html ( ) ) ;
99
+ console . log ( options . at ( 2 ) . html ( ) ) ;
100
+ console . log ( options . at ( 3 ) . html ( ) ) ;
101
+ console . log ( options . at ( 4 ) . html ( ) ) ;
102
+
103
+ expect ( options . length ) . to . be . equal ( 4 ) ; // no <non selected>
99
104
} ) ;
100
105
} ) ;
101
106
@@ -112,46 +117,37 @@ describe.skip("fieldSelectEx.vue", function() {
112
117
]
113
118
} ;
114
119
let model = { city : [ 2 ] } ;
115
- let input ;
116
120
117
121
before ( ( ) => {
118
- createField ( this , schema , model , false ) ;
119
- input = el . getElementsByTagName ( "select" ) [ 0 ] ;
122
+ createField2 ( { schema, model, disabled : false } ) ;
120
123
} ) ;
121
124
122
- it ( "should contain option elements" , ( ) => {
123
- let options = input . querySelectorAll ( "option" ) ;
124
- expect ( options . length ) . to . be . equal ( 4 + 1 ) ; // +1 for <non selected>
125
+ it . skip ( "should contain option elements" , ( ) => {
126
+ let options = input . findAll ( "option" ) ;
125
127
126
- expect ( options [ 2 ] . value ) . to . be . equal ( "2" ) ;
127
- expect ( options [ 2 ] . textContent ) . to . be . equal ( "Paris" ) ;
128
- expect ( options [ 2 ] . selected ) . to . be . true ;
129
- expect ( options [ 1 ] . selected ) . to . be . false ;
128
+ expect ( options . length ) . to . be . equal ( 4 + 1 ) ; // +1 for <non selected>
129
+ expect ( options . at ( 2 ) . element . value ) . to . be . equal ( "2" ) ;
130
+ expect ( options . at ( 2 ) . text ( ) ) . to . be . equal ( "Paris" ) ;
131
+ expect ( options . at ( 2 ) . element . selected ) . to . be . true ;
132
+ expect ( options . at ( 1 ) . element . selected ) . to . be . false ;
130
133
} ) ;
131
134
132
- it ( "should contain the value" , done => {
133
- vm . $nextTick ( ( ) => {
134
- expect ( input . value ) . to . be . equal ( "2" ) ;
135
- done ( ) ;
136
- } ) ;
135
+ it . skip ( "should contain the value" , ( ) => {
136
+ expect ( input . element . value ) . to . be . equal ( "2" ) ;
137
137
} ) ;
138
138
139
- it ( "input value should be the model value after changed" , done => {
139
+ it ( "input value should be the model value after changed" , ( ) => {
140
140
model . city = 3 ;
141
- vm . $nextTick ( ( ) => {
142
- expect ( input . value ) . to . be . equal ( "3" ) ;
143
- done ( ) ;
144
- } ) ;
141
+ wrapper . update ( ) ;
142
+
143
+ expect ( input . element . value ) . to . be . equal ( "3" ) ;
145
144
} ) ;
146
145
147
- it ( "model value should be the input value if changed" , done => {
148
- input . value = "4" ;
149
- trigger ( input , "change" ) ;
146
+ it ( "model value should be the input value if changed" , ( ) => {
147
+ input . element . value = "4" ;
148
+ input . trigger ( "change" ) ;
150
149
151
- vm . $nextTick ( ( ) => {
152
- expect ( model . city ) . to . be . equal ( 4 ) ;
153
- done ( ) ;
154
- } ) ;
150
+ expect ( model . city ) . to . be . equal ( 4 ) ;
155
151
} ) ;
156
152
} ) ;
157
153
@@ -170,36 +166,26 @@ describe.skip("fieldSelectEx.vue", function() {
170
166
}
171
167
} ;
172
168
let model = { city : [ 2 ] } ;
173
- let input ;
174
169
175
170
before ( ( ) => {
176
- createField ( this , schema , model , false ) ;
177
- input = el . getElementsByTagName ( "select" ) [ 0 ] ;
171
+ createField2 ( { schema, model, disabled : false } ) ;
172
+ wrapper . update ( ) ;
178
173
} ) ;
179
174
180
- it ( "should contain the value" , done => {
181
- vm . $nextTick ( ( ) => {
182
- expect ( input . value ) . to . be . equal ( "2" ) ;
183
- done ( ) ;
184
- } ) ;
175
+ it . skip ( "should contain the value" , ( ) => {
176
+ expect ( input . element . value ) . to . be . equal ( "2" ) ;
185
177
} ) ;
186
178
187
- it ( "input value should be the model value after changed" , done => {
179
+ it ( "input value should be the model value after changed" , ( ) => {
188
180
model . city = 3 ;
189
- vm . $nextTick ( ( ) => {
190
- expect ( input . value ) . to . be . equal ( "3" ) ;
191
- done ( ) ;
192
- } ) ;
181
+ wrapper . update ( ) ;
182
+ expect ( input . element . value ) . to . be . equal ( "3" ) ;
193
183
} ) ;
194
184
195
- it ( "model value should be the input value if changed" , done => {
196
- input . value = "4" ;
197
- trigger ( input , "change" ) ;
198
-
199
- vm . $nextTick ( ( ) => {
200
- expect ( model . city ) . to . be . equal ( 4 ) ;
201
- done ( ) ;
202
- } ) ;
185
+ it ( "model value should be the input value if changed" , ( ) => {
186
+ input . element . value = "4" ;
187
+ input . trigger ( "change" ) ;
188
+ expect ( model . city ) . to . be . equal ( 4 ) ;
203
189
} ) ;
204
190
} ) ;
205
191
} ) ;
0 commit comments