Skip to content

Commit 1b24293

Browse files
author
Lionel Bijaoui
committed
test: improve unit testing of vueMultiSelect
1 parent 9a6fc4b commit 1b24293

File tree

1 file changed

+56
-5
lines changed

1 file changed

+56
-5
lines changed

test/unit/specs/fields/fieldVueMultiSelect.spec.js

+56-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from "chai";
2-
import { createVueField } from "../util";
2+
import { createVueField, trigger } from "../util";
33

44
import Vue from "vue";
55
import fieldVueMultiSelect from "src/fields/fieldVueMultiSelect.vue";
@@ -20,7 +20,7 @@ describe("fieldVueMultiSelect.vue", () => {
2020
type: "vueMultiSelect",
2121
label: "Cities",
2222
model: "city",
23-
multiSelect: false,
23+
multiSelect: true,
2424
required: false,
2525
values: [
2626
"London",
@@ -35,16 +35,67 @@ describe("fieldVueMultiSelect.vue", () => {
3535

3636
before( () => {
3737
createField(schema, model, false);
38-
input = el.getElementsByTagName("select")[0];
38+
vm.$appendTo(document.body);
39+
input = el.querySelector(".multiselect");
3940
});
4041

4142
it("should contain a select element", () => {
4243
expect(field).to.be.exist;
4344
expect(field.$el).to.be.exist;
4445

4546
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+
4899
});
49100
});
50101
});

0 commit comments

Comments
 (0)