-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathfieldSelectEx.spec.js
190 lines (154 loc) · 4.7 KB
/
fieldSelectEx.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { mount, createLocalVue } from "@vue/test-utils";
import FieldSelectEx from "src/fields/optional/fieldSelectEx.vue";
const localVue = createLocalVue();
let wrapper;
let input;
function createField2(data, methods) {
const _wrapper = mount(FieldSelectEx, {
localVue,
propsData: data,
methods: methods
});
wrapper = _wrapper;
input = wrapper.find("select");
return _wrapper;
}
describe("fieldSelectEx.vue", () => {
describe("check template", () => {
let schema = {
type: "selectEx",
label: "Cities",
model: "city",
disabled: false,
multiSelect: false,
required: false,
inputName: "",
values: ["London", "Paris", "Rome", "Berlin"]
};
let model = { city: "Paris" };
before(() => {
createField2({ schema, model, disabled: false });
});
it("should contain a select element", () => {
expect(wrapper.exists()).to.be.true;
expect(input.exists()).to.be.true;
});
it("should contain option elements", () => {
let options = input.findAll("option");
expect(options.length).to.be.equal(4 + 1); // +1 for <non selected>
expect(options.at(2).element.value).to.be.equal("Paris");
expect(options.at(2).text()).to.be.equal("Paris");
expect(options.at(2).element.selected).to.be.true;
});
it("should contain a <non selected> element", () => {
let options = input.findAll("option");
expect(options.at(0).attributes().disabled).to.be.undefined;
// expect(options.at(0).text()).to.be.equal("<Not selected>");
});
it("should contain the value", () => {
expect(input.element.value).to.be.equal("Paris");
});
describe("check optional attribute", () => {
let attributes = ["disabled", "multiSelect", "inputName"];
attributes.forEach(name => {
it("should set " + name, () => {
checkAttribute(name, wrapper, schema, "select");
});
});
});
it("input value should be the model value after changed", () => {
model.city = "Rome";
wrapper.update();
expect(input.element.value).to.be.equal("Rome");
});
it("model value should be the input value if changed", () => {
input.element.value = "London";
input.trigger("change");
expect(model.city).to.be.equal("London");
});
it.skip("should not be multiple", () => {
model.city = []; // For multiselect need empty array
schema.multiSelect = true;
wrapper.update();
expect(input.attributes().multiple).to.equal("multiple");
let options = input.findAll("option");
console.log(options.at(0).html());
console.log(options.at(1).html());
console.log(options.at(2).html());
console.log(options.at(3).html());
console.log(options.at(4).html());
expect(options.length).to.be.equal(4); // no <non selected>
});
});
describe("check static values with { id, name } objects", () => {
let schema = {
type: "select",
label: "Cities",
model: "city",
values: [
{ id: 1, name: "London" },
{ id: 2, name: "Paris" },
{ id: 3, name: "Rome" },
{ id: 4, name: "Berlin" }
]
};
let model = { city: [2] };
before(() => {
createField2({ schema, model, disabled: false });
});
it.skip("should contain option elements", () => {
let options = input.findAll("option");
expect(options.length).to.be.equal(4 + 1); // +1 for <non selected>
expect(options.at(2).element.value).to.be.equal("2");
expect(options.at(2).text()).to.be.equal("Paris");
expect(options.at(2).element.selected).to.be.true;
expect(options.at(1).element.selected).to.be.false;
});
it.skip("should contain the value", () => {
expect(input.element.value).to.be.equal("2");
});
it("input value should be the model value after changed", () => {
model.city = 3;
wrapper.update();
expect(input.element.value).to.be.equal("3");
});
it("model value should be the input value if changed", () => {
input.element.value = "4";
input.trigger("change");
expect(model.city).to.be.equal(4);
});
});
describe("check function values", () => {
let schema = {
type: "select",
label: "Cities",
model: "city",
values() {
return [
{ id: 1, name: "London" },
{ id: 2, name: "Paris" },
{ id: 3, name: "Rome" },
{ id: 4, name: "Berlin" }
];
}
};
let model = { city: [2] };
before(() => {
createField2({ schema, model, disabled: false });
wrapper.update();
});
it.skip("should contain the value", () => {
expect(input.element.value).to.be.equal("2");
});
it("input value should be the model value after changed", () => {
model.city = 3;
wrapper.update();
expect(input.element.value).to.be.equal("3");
});
it("model value should be the input value if changed", () => {
input.element.value = "4";
input.trigger("change");
expect(model.city).to.be.equal(4);
});
});
});