Skip to content

Commit

Permalink
✅ test: Make abstractField test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed May 8, 2016
1 parent ba41387 commit 564963f
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/fields/abstractField.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export default {

watch: {
value: function(newVal, oldVal) {
//console.log("Value changed!");

if (isFunction(this.schema.onChanged)) {
this.schema.onChanged(this.model, newVal, oldVal, this.schema);
}
Expand Down
87 changes: 87 additions & 0 deletions test/unit/specs/fields/abstractField.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//import chai from "chai";
import { expect } from "chai";

//import sinon from "sinon";
//import sinonChai from "sinon-chai";
//chai.use(sinonChai);

import Vue from "vue";
import AbstractField from "src/fields/abstractField";

Vue.component("AbstractField", AbstractField);

let el, vm, field;

function createField(schema = {}, model = null, disabled = false) {
el = document.createElement("div");
el.innerHTML = `<abstract-field :schema="schema" :model="model" :disabled="disabled" v-ref:field></abstract-field>`;
vm = new Vue({
el: el,
data: {
schema,
model,
disabled
}
});

field = vm.$refs.field;
// console.log(el);

return [el, vm];
}

describe("abstractField", () => {

describe("check static value", () => {
let schema = {
type: "text",
label: "Name",
model: "name"
};
let model = { name: "John Doe" };

beforeEach( () => {
createField(schema, model);
});

it("should give the model static value", () => {
expect(field).to.be.exist;
expect(field.value).to.be.equal("John Doe");
});

it("should set new value to model if value changed", () => {
field.value = "Foo Bar";
expect(model.name).to.be.equal("Foo Bar");
});

});

/*describe("check value as get/set function", () => {
let schema = {
type: "text",
label: "Name",
model: "name",
get(model) {
return "John Smith"
},
set: sinon.spy()
};
let model = {};
beforeEach( () => {
createField(schema, model);
});
it("should give the model static value", () => {
expect(field).to.be.exist;
expect(field.value).to.be.equal("John Doe");
});
it("should set new value to model if value changed", () => {
field.value = "Foo Bar";
expect(model.name).to.be.equal("Foo Bar");
});
});*/

});

0 comments on commit 564963f

Please sign in to comment.