forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldVueMultiSelect.spec.js
103 lines (87 loc) · 3.21 KB
/
fieldVueMultiSelect.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { expect } from "chai";
import { createVueField, trigger } from "../util";
import Vue from "vue";
import fieldVueMultiSelect from "src/fields/fieldVueMultiSelect.vue";
Vue.component("fieldVueMultiSelect", fieldVueMultiSelect);
// eslint-disable-next-line
let el, vm, field;
function createField(schema = {}, model = null, disabled = false, options) {
[ el, vm, field ] = createVueField("fieldVueMultiSelect", schema, model, disabled, options);
}
describe("fieldVueMultiSelect.vue", () => {
describe("check template", () => {
let schema = {
type: "vueMultiSelect",
label: "Cities",
model: "city",
multiSelect: true,
required: false,
values: [
"London",
"Paris",
"Rome",
"Berlin"
],
selectOptions: {}
};
let model = { city: "Paris" };
let input;
before( () => {
createField(schema, model, false);
vm.$appendTo(document.body);
input = el.querySelector(".multiselect");
});
it("should contain a select element", () => {
expect(field).to.be.exist;
expect(field.$el).to.be.exist;
expect(input).to.be.defined;
expect(input.classList.contains("form-control")).to.be.false;
expect(input.classList.contains("multiselect--disabled")).to.be.false;
});
it("should contain option elements", () => {
let options = input.querySelectorAll("li.multiselect__option");
expect(options.length).to.be.equal(schema.values.length);
expect(options[1].querySelector("span").textContent).to.be.equal("Paris");
expect(options[1].classList.contains("multiselect__option--selected")).to.be.true;
});
it("should set disabled", (done) => {
field.disabled = true;
vm.$nextTick( () => {
expect(input.classList.contains("multiselect--disabled")).to.be.true;
field.disabled = false;
done();
});
});
it("input value should be the model value after changed", (done) => {
model.city = "Rome";
vm.$nextTick( () => {
expect(input.querySelectorAll("li.multiselect__option--selected").length).to.be.equal(1);
let options = input.querySelectorAll("li.multiselect__option");
expect(options[2].querySelector("span").textContent).to.be.equal("Rome");
expect(options[2].classList.contains("multiselect__option--selected")).to.be.true;
done();
});
});
it("input value should be the model value after changed (multiselection)", (done) => {
model.city = ["Paris","Rome"];
vm.$nextTick( () => {
expect(input.querySelectorAll("li.multiselect__option--selected").length).to.be.equal(2);
let options = input.querySelectorAll("li.multiselect__option");
expect(options[1].querySelector("span").textContent).to.be.equal("Paris");
expect(options[1].classList.contains("multiselect__option--selected")).to.be.true;
expect(options[2].querySelector("span").textContent).to.be.equal("Rome");
expect(options[2].classList.contains("multiselect__option--selected")).to.be.true;
done();
});
});
it("model value should be the input value if changed", (done) => {
let options = input.querySelectorAll("li.multiselect__option");
trigger(options[2], "mousedown");
vm.$nextTick( () => {
expect(model.city.length).to.be.equal(1);
expect(model.city[0]).to.be.equal("Paris");
done();
});
});
});
});