Skip to content

Commit

Permalink
add test for radios field and update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Bijaoui committed Sep 27, 2016
1 parent b00e777 commit 07605c1
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dev/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ module.exports = {
model: "radios",
values: [
{name: "HTML5", value:"HTML5-123"},
{name: "Javascript", value:{id:"Javascript-123", deep:true}},
{name: "Javascript", value:"Javascript-123"},
{name: "CSS3", value:"CSS3-123"},
{name: "CoffeeScript", value:"CoffeeScript-123"},
{name: "AngularJS", value:"AngularJS-123"},
Expand Down
174 changes: 174 additions & 0 deletions test/unit/specs/fields/fieldRadios.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
});

});

});

});

0 comments on commit 07605c1

Please sign in to comment.