1- import { createVueField , trigger , checkAttribute } from "../util" ;
1+ import { mount , createLocalVue } from "@vue/test-utils" ;
2+ import { checkAttribute2 } from "../util" ;
23
3- import Vue from "vue" ;
44import FieldSelectEx from "src/fields/optional/fieldSelectEx.vue" ;
55
6- Vue . component ( "FieldSelectEx" , FieldSelectEx ) ;
6+ const localVue = createLocalVue ( ) ;
7+ let wrapper ;
8+ let input ;
79
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" ) ;
919
10- function createField ( test , schema = { } , model = null , disabled = false , options ) {
11- [ el , vm , field ] = createVueField ( test , "fieldSelectEx" , schema , model , disabled , options ) ;
20+ return _wrapper ;
1221}
1322
14- describe . skip ( "fieldSelectEx.vue" , function ( ) {
23+ describe ( "fieldSelectEx.vue" , ( ) => {
1524 describe ( "check template" , ( ) => {
1625 let schema = {
1726 type : "selectEx" ,
1827 label : "Cities" ,
1928 model : "city" ,
29+ disabled : false ,
2030 multiSelect : false ,
2131 required : false ,
32+ inputName : "" ,
2233 values : [ "London" , "Paris" , "Rome" , "Berlin" ]
2334 } ;
2435 let model = { city : "Paris" } ;
25- let input ;
2636
2737 before ( ( ) => {
28- createField ( this , schema , model , false ) ;
29- input = el . getElementsByTagName ( "select" ) [ 0 ] ;
38+ createField2 ( { schema, model, disabled : false } ) ;
3039 } ) ;
3140
3241 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 ;
3744 } ) ;
3845
3946 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" ) ;
4248
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 ;
4653 } ) ;
4754
4855 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>");
5260 } ) ;
5361
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" ) ;
5964 } ) ;
6065
6166 describe ( "check optional attribute" , ( ) => {
6267 let attributes = [ "disabled" , "multiSelect" , "inputName" ] ;
6368
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" ) ;
6772 } ) ;
6873 } ) ;
6974 } ) ;
7075
71- it ( "input value should be the model value after changed" , done => {
76+ it ( "input value should be the model value after changed" , ( ) => {
7277 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" ) ;
7781 } ) ;
7882
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" ) ;
8286
83- vm . $nextTick ( ( ) => {
84- expect ( model . city ) . to . be . equal ( "London" ) ;
85- done ( ) ;
86- } ) ;
87+ expect ( model . city ) . to . be . equal ( "London" ) ;
8788 } ) ;
8889
89- it ( "should not be multiple" , done => {
90+ it . skip ( "should not be multiple" , ( ) => {
9091 model . city = [ ] ; // For multiselect need empty array
9192 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 ( ) ;
9694
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>
99104 } ) ;
100105 } ) ;
101106
@@ -112,46 +117,37 @@ describe.skip("fieldSelectEx.vue", function() {
112117 ]
113118 } ;
114119 let model = { city : [ 2 ] } ;
115- let input ;
116120
117121 before ( ( ) => {
118- createField ( this , schema , model , false ) ;
119- input = el . getElementsByTagName ( "select" ) [ 0 ] ;
122+ createField2 ( { schema, model, disabled : false } ) ;
120123 } ) ;
121124
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" ) ;
125127
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 ;
130133 } ) ;
131134
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" ) ;
137137 } ) ;
138138
139- it ( "input value should be the model value after changed" , done => {
139+ it ( "input value should be the model value after changed" , ( ) => {
140140 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" ) ;
145144 } ) ;
146145
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" ) ;
150149
151- vm . $nextTick ( ( ) => {
152- expect ( model . city ) . to . be . equal ( 4 ) ;
153- done ( ) ;
154- } ) ;
150+ expect ( model . city ) . to . be . equal ( 4 ) ;
155151 } ) ;
156152 } ) ;
157153
@@ -170,36 +166,26 @@ describe.skip("fieldSelectEx.vue", function() {
170166 }
171167 } ;
172168 let model = { city : [ 2 ] } ;
173- let input ;
174169
175170 before ( ( ) => {
176- createField ( this , schema , model , false ) ;
177- input = el . getElementsByTagName ( "select" ) [ 0 ] ;
171+ createField2 ( { schema, model, disabled : false } ) ;
172+ wrapper . update ( ) ;
178173 } ) ;
179174
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" ) ;
185177 } ) ;
186178
187- it ( "input value should be the model value after changed" , done => {
179+ it ( "input value should be the model value after changed" , ( ) => {
188180 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" ) ;
193183 } ) ;
194184
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 ) ;
203189 } ) ;
204190 } ) ;
205191} ) ;
0 commit comments