From 564963fdabba8ef5ef70769c97cc7cdcdb8ea760 Mon Sep 17 00:00:00 2001 From: Icebob Date: Sun, 8 May 2016 23:42:23 +0200 Subject: [PATCH] :white_check_mark: test: Make abstractField test cases --- src/fields/abstractField.js | 2 - test/unit/specs/fields/abstractField.spec.js | 87 ++++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 test/unit/specs/fields/abstractField.spec.js diff --git a/src/fields/abstractField.js b/src/fields/abstractField.js index 093b14f8..14cc0249 100644 --- a/src/fields/abstractField.js +++ b/src/fields/abstractField.js @@ -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); } diff --git a/test/unit/specs/fields/abstractField.spec.js b/test/unit/specs/fields/abstractField.spec.js new file mode 100644 index 00000000..0701cd82 --- /dev/null +++ b/test/unit/specs/fields/abstractField.spec.js @@ -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 = ``; + 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"); + }); + + });*/ + +}); \ No newline at end of file