forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldRadios.spec.js
174 lines (143 loc) · 4.13 KB
/
fieldRadios.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
import { expect } from "chai";
import { createVueField } from "../util";
import Vue from "vue";
import FieldRadios from "src/fields/fieldRadios.vue";
Vue.component("FieldRadios", FieldRadios);
let el, vm, field;
function createField(test, schema = {}, model = null, disabled = false, options) {
[ el, vm, field ] = createVueField(test, "fieldRadios", schema, model, disabled, options);
}
describe("FieldRadios.vue", function() {
describe("check template with static string array", () => {
let schema = {
type: "radios",
label: "radios",
model: "skills",
values: [
"HTML5",
"Javascript",
"CSS3",
"CoffeeScript",
"AngularJS",
"ReactJS",
"VueJS"
]
};
let model = { skills: "Javascript" };
let radioList;
let radios;
function isChecked(idx) {
return(radios[idx].checked);
}
before( () => {
createField(this, schema, model, false);
radioList = el.querySelector(".radio-list");
radios = radioList.querySelectorAll("input[type=radio]");
});
it("should contain a checkbox element", () => {
expect(field).to.be.exist;
expect(field.$el).to.be.exist;
expect(radioList).to.be.defined;
});
it("should contain 7 items", () => {
expect(radios.length).to.be.equal(7);
});
it("should checked the values", () => {
expect(isChecked(0)).to.be.false;
expect(isChecked(1)).to.be.true;
expect(isChecked(2)).to.be.false;
expect(isChecked(3)).to.be.false;
expect(isChecked(4)).to.be.false;
expect(isChecked(5)).to.be.false;
expect(isChecked(6)).to.be.false;
});
it("radioList value should be the model value after changed", (done) => {
model.skills = "ReactJS";
vm.$nextTick( () => {
expect(isChecked(0)).to.be.false;
expect(isChecked(1)).to.be.false;
expect(isChecked(2)).to.be.false;
expect(isChecked(3)).to.be.false;
expect(isChecked(4)).to.be.false;
expect(isChecked(5)).to.be.true;
expect(isChecked(6)).to.be.false;
done();
});
});
it("model value should be the radioList value if changed", (done) => {
radios[0].click();
vm.$nextTick( () => {
expect(model.skills).to.be.equal("HTML5");
done();
});
});
});
describe("check template with object array", () => {
let schema = {
type: "radios",
label: "radios",
model: "skills",
values: [
{name: "HTML5", value:"HTML5-123"},
{name: "Javascript", value:{id:"Javascript-123", deep:true}},
{name: "CSS3", value:"CSS3-123"},
{name: "CoffeeScript", value:"CoffeeScript-123"},
{name: "AngularJS", value:"AngularJS-123"},
{name: "ReactJS", value:"ReactJS-123"},
{name: "VueJS", value:"VueJS-123"}
],
radiosOptions: {
value:"value",
name:"name"
}
};
let model = { skills: "CSS3-123" };
let radioList;
let radios;
function isChecked(idx) {
return(radios[idx].checked);
}
before( () => {
createField(this, schema, model, false);
radioList = el.querySelector(".radio-list");
radios = radioList.querySelectorAll("input[type=radio]");
});
it("should contain a checkbox element", () => {
expect(field).to.be.exist;
expect(field.$el).to.be.exist;
expect(radioList).to.be.defined;
});
it("should contain 7 items", () => {
expect(radios.length).to.be.equal(7);
});
it("should checked the values", () => {
expect(isChecked(0)).to.be.false;
expect(isChecked(1)).to.be.false;
expect(isChecked(2)).to.be.true;
expect(isChecked(3)).to.be.false;
expect(isChecked(4)).to.be.false;
expect(isChecked(5)).to.be.false;
expect(isChecked(6)).to.be.false;
});
it("radioList value should be the model value after changed", (done) => {
model.skills = "ReactJS-123";
vm.$nextTick( () => {
expect(isChecked(0)).to.be.false;
expect(isChecked(1)).to.be.false;
expect(isChecked(2)).to.be.false;
expect(isChecked(3)).to.be.false;
expect(isChecked(4)).to.be.false;
expect(isChecked(5)).to.be.true;
expect(isChecked(6)).to.be.false;
done();
});
});
it("model value should be the radioList value if changed", (done) => {
radios[0].click();
vm.$nextTick( () => {
expect(model.skills).to.be.equal("HTML5-123");
done();
});
});
});
});