Skip to content

Commit 07605c1

Browse files
author
Lionel Bijaoui
committed
add test for radios field and update schema
1 parent b00e777 commit 07605c1

File tree

2 files changed

+175
-1
lines changed

2 files changed

+175
-1
lines changed

dev/schema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ module.exports = {
224224
model: "radios",
225225
values: [
226226
{name: "HTML5", value:"HTML5-123"},
227-
{name: "Javascript", value:{id:"Javascript-123", deep:true}},
227+
{name: "Javascript", value:"Javascript-123"},
228228
{name: "CSS3", value:"CSS3-123"},
229229
{name: "CoffeeScript", value:"CoffeeScript-123"},
230230
{name: "AngularJS", value:"AngularJS-123"},
+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { expect } from "chai";
2+
import { createVueField } from "../util";
3+
4+
import Vue from "vue";
5+
import FieldRadios from "src/fields/fieldRadios.vue";
6+
7+
Vue.component("FieldRadios", FieldRadios);
8+
9+
let el, vm, field;
10+
11+
function createField(test, schema = {}, model = null, disabled = false, options) {
12+
[ el, vm, field ] = createVueField(test, "fieldRadios", schema, model, disabled, options);
13+
}
14+
15+
describe("FieldRadios.vue", function() {
16+
17+
describe("check template with static string array", () => {
18+
let schema = {
19+
type: "radios",
20+
label: "radios",
21+
model: "skills",
22+
values: [
23+
"HTML5",
24+
"Javascript",
25+
"CSS3",
26+
"CoffeeScript",
27+
"AngularJS",
28+
"ReactJS",
29+
"VueJS"
30+
]
31+
};
32+
let model = { skills: "Javascript" };
33+
let radioList;
34+
let radios;
35+
36+
function isChecked(idx) {
37+
return(radios[idx].checked);
38+
}
39+
40+
before( () => {
41+
createField(this, schema, model, false);
42+
radioList = el.querySelector(".radio-list");
43+
radios = radioList.querySelectorAll("input[type=radio]");
44+
});
45+
46+
it("should contain a checkbox element", () => {
47+
expect(field).to.be.exist;
48+
expect(field.$el).to.be.exist;
49+
50+
expect(radioList).to.be.defined;
51+
});
52+
53+
it("should contain 7 items", () => {
54+
expect(radios.length).to.be.equal(7);
55+
});
56+
57+
it("should checked the values", () => {
58+
expect(isChecked(0)).to.be.false;
59+
expect(isChecked(1)).to.be.true;
60+
expect(isChecked(2)).to.be.false;
61+
expect(isChecked(3)).to.be.false;
62+
expect(isChecked(4)).to.be.false;
63+
expect(isChecked(5)).to.be.false;
64+
expect(isChecked(6)).to.be.false;
65+
});
66+
67+
it("radioList value should be the model value after changed", (done) => {
68+
model.skills = "ReactJS";
69+
vm.$nextTick( () => {
70+
expect(isChecked(0)).to.be.false;
71+
expect(isChecked(1)).to.be.false;
72+
expect(isChecked(2)).to.be.false;
73+
expect(isChecked(3)).to.be.false;
74+
expect(isChecked(4)).to.be.false;
75+
expect(isChecked(5)).to.be.true;
76+
expect(isChecked(6)).to.be.false;
77+
done();
78+
});
79+
80+
});
81+
82+
it("model value should be the radioList value if changed", (done) => {
83+
radios[0].click();
84+
85+
vm.$nextTick( () => {
86+
expect(model.skills).to.be.equal("HTML5");
87+
done();
88+
});
89+
90+
});
91+
92+
});
93+
94+
describe("check template with object array", () => {
95+
let schema = {
96+
type: "radios",
97+
label: "radios",
98+
model: "skills",
99+
values: [
100+
{name: "HTML5", value:"HTML5-123"},
101+
{name: "Javascript", value:{id:"Javascript-123", deep:true}},
102+
{name: "CSS3", value:"CSS3-123"},
103+
{name: "CoffeeScript", value:"CoffeeScript-123"},
104+
{name: "AngularJS", value:"AngularJS-123"},
105+
{name: "ReactJS", value:"ReactJS-123"},
106+
{name: "VueJS", value:"VueJS-123"}
107+
],
108+
radiosOptions: {
109+
value:"value",
110+
name:"name"
111+
}
112+
};
113+
let model = { skills: "CSS3-123" };
114+
let radioList;
115+
let radios;
116+
117+
function isChecked(idx) {
118+
return(radios[idx].checked);
119+
}
120+
121+
before( () => {
122+
createField(this, schema, model, false);
123+
radioList = el.querySelector(".radio-list");
124+
radios = radioList.querySelectorAll("input[type=radio]");
125+
});
126+
127+
it("should contain a checkbox element", () => {
128+
expect(field).to.be.exist;
129+
expect(field.$el).to.be.exist;
130+
131+
expect(radioList).to.be.defined;
132+
});
133+
134+
it("should contain 7 items", () => {
135+
expect(radios.length).to.be.equal(7);
136+
});
137+
138+
it("should checked the values", () => {
139+
expect(isChecked(0)).to.be.false;
140+
expect(isChecked(1)).to.be.false;
141+
expect(isChecked(2)).to.be.true;
142+
expect(isChecked(3)).to.be.false;
143+
expect(isChecked(4)).to.be.false;
144+
expect(isChecked(5)).to.be.false;
145+
expect(isChecked(6)).to.be.false;
146+
});
147+
148+
it("radioList value should be the model value after changed", (done) => {
149+
model.skills = "ReactJS-123";
150+
vm.$nextTick( () => {
151+
expect(isChecked(0)).to.be.false;
152+
expect(isChecked(1)).to.be.false;
153+
expect(isChecked(2)).to.be.false;
154+
expect(isChecked(3)).to.be.false;
155+
expect(isChecked(4)).to.be.false;
156+
expect(isChecked(5)).to.be.true;
157+
expect(isChecked(6)).to.be.false;
158+
done();
159+
});
160+
});
161+
162+
it("model value should be the radioList value if changed", (done) => {
163+
radios[0].click();
164+
165+
vm.$nextTick( () => {
166+
expect(model.skills).to.be.equal("HTML5-123");
167+
done();
168+
});
169+
170+
});
171+
172+
});
173+
174+
});

0 commit comments

Comments
 (0)