1
1
import { expect } from "chai" ;
2
- import { createVueField } from "../util" ;
2
+ import { createVueField , trigger } from "../util" ;
3
3
4
4
import Vue from "vue" ;
5
5
import fieldVueMultiSelect from "src/fields/fieldVueMultiSelect.vue" ;
@@ -20,7 +20,7 @@ describe("fieldVueMultiSelect.vue", () => {
20
20
type : "vueMultiSelect" ,
21
21
label : "Cities" ,
22
22
model : "city" ,
23
- multiSelect : false ,
23
+ multiSelect : true ,
24
24
required : false ,
25
25
values : [
26
26
"London" ,
@@ -35,16 +35,67 @@ describe("fieldVueMultiSelect.vue", () => {
35
35
36
36
before ( ( ) => {
37
37
createField ( schema , model , false ) ;
38
- input = el . getElementsByTagName ( "select" ) [ 0 ] ;
38
+ vm . $appendTo ( document . body ) ;
39
+ input = el . querySelector ( ".multiselect" ) ;
39
40
} ) ;
40
41
41
42
it ( "should contain a select element" , ( ) => {
42
43
expect ( field ) . to . be . exist ;
43
44
expect ( field . $el ) . to . be . exist ;
44
45
45
46
expect ( input ) . to . be . defined ;
46
- // expect(input.classList.contains("form-control")).to.be.false;
47
- // expect(input.disabled).to.be.false;
47
+ expect ( input . classList . contains ( "form-control" ) ) . to . be . false ;
48
+ expect ( input . classList . contains ( "multiselect--disabled" ) ) . to . be . false ;
49
+ } ) ;
50
+
51
+ it ( "should contain option elements" , ( ) => {
52
+ let options = input . querySelectorAll ( "li.multiselect__option" ) ;
53
+ console . log ( options ) ;
54
+ expect ( options . length ) . to . be . equal ( schema . values . length ) ;
55
+ expect ( options [ 1 ] . querySelector ( "span" ) . textContent ) . to . be . equal ( "Paris" ) ;
56
+ expect ( options [ 1 ] . classList . contains ( "multiselect__option--selected" ) ) . to . be . true ;
57
+ } ) ;
58
+
59
+ it ( "should set disabled" , ( done ) => {
60
+ field . disabled = true ;
61
+ vm . $nextTick ( ( ) => {
62
+ expect ( input . classList . contains ( "multiselect--disabled" ) ) . to . be . true ;
63
+ field . disabled = false ;
64
+ done ( ) ;
65
+ } ) ;
66
+ } ) ;
67
+
68
+ it ( "input value should be the model value after changed" , ( done ) => {
69
+ model . city = "Rome" ;
70
+ vm . $nextTick ( ( ) => {
71
+ let options = input . querySelectorAll ( "li.multiselect__option" ) ;
72
+ expect ( options [ 2 ] . querySelector ( "span" ) . textContent ) . to . be . equal ( "Rome" ) ;
73
+ expect ( options [ 2 ] . classList . contains ( "multiselect__option--selected" ) ) . to . be . true ;
74
+ done ( ) ;
75
+ } ) ;
76
+ } ) ;
77
+
78
+ it ( "input value should be the model value after changed (multiselection)" , ( done ) => {
79
+ model . city = [ "Paris" , "Rome" ] ;
80
+ vm . $nextTick ( ( ) => {
81
+ let options = input . querySelectorAll ( "li.multiselect__option" ) ;
82
+ expect ( options [ 1 ] . querySelector ( "span" ) . textContent ) . to . be . equal ( "Paris" ) ;
83
+ expect ( options [ 1 ] . classList . contains ( "multiselect__option--selected" ) ) . to . be . true ;
84
+ expect ( options [ 2 ] . querySelector ( "span" ) . textContent ) . to . be . equal ( "Rome" ) ;
85
+ expect ( options [ 2 ] . classList . contains ( "multiselect__option--selected" ) ) . to . be . true ;
86
+ done ( ) ;
87
+ } ) ;
88
+ } ) ;
89
+
90
+ it ( "model value should be the input value if changed" , ( done ) => {
91
+ let options = input . querySelectorAll ( "li.multiselect__option" ) ;
92
+ trigger ( options [ 2 ] , "mousedown" ) ;
93
+
94
+ vm . $nextTick ( ( ) => {
95
+ expect ( model . city [ 0 ] ) . to . be . equal ( "Paris" ) ;
96
+ done ( ) ;
97
+ } ) ;
98
+
48
99
} ) ;
49
100
} ) ;
50
101
} ) ;
0 commit comments