Skip to content

Commit 564963f

Browse files
committed
✅ test: Make abstractField test cases
1 parent ba41387 commit 564963f

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

src/fields/abstractField.js

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export default {
4040

4141
watch: {
4242
value: function(newVal, oldVal) {
43-
//console.log("Value changed!");
44-
4543
if (isFunction(this.schema.onChanged)) {
4644
this.schema.onChanged(this.model, newVal, oldVal, this.schema);
4745
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//import chai from "chai";
2+
import { expect } from "chai";
3+
4+
//import sinon from "sinon";
5+
//import sinonChai from "sinon-chai";
6+
//chai.use(sinonChai);
7+
8+
import Vue from "vue";
9+
import AbstractField from "src/fields/abstractField";
10+
11+
Vue.component("AbstractField", AbstractField);
12+
13+
let el, vm, field;
14+
15+
function createField(schema = {}, model = null, disabled = false) {
16+
el = document.createElement("div");
17+
el.innerHTML = `<abstract-field :schema="schema" :model="model" :disabled="disabled" v-ref:field></abstract-field>`;
18+
vm = new Vue({
19+
el: el,
20+
data: {
21+
schema,
22+
model,
23+
disabled
24+
}
25+
});
26+
27+
field = vm.$refs.field;
28+
// console.log(el);
29+
30+
return [el, vm];
31+
}
32+
33+
describe("abstractField", () => {
34+
35+
describe("check static value", () => {
36+
let schema = {
37+
type: "text",
38+
label: "Name",
39+
model: "name"
40+
};
41+
let model = { name: "John Doe" };
42+
43+
beforeEach( () => {
44+
createField(schema, model);
45+
});
46+
47+
it("should give the model static value", () => {
48+
expect(field).to.be.exist;
49+
expect(field.value).to.be.equal("John Doe");
50+
});
51+
52+
it("should set new value to model if value changed", () => {
53+
field.value = "Foo Bar";
54+
expect(model.name).to.be.equal("Foo Bar");
55+
});
56+
57+
});
58+
59+
/*describe("check value as get/set function", () => {
60+
let schema = {
61+
type: "text",
62+
label: "Name",
63+
model: "name",
64+
get(model) {
65+
return "John Smith"
66+
},
67+
set: sinon.spy()
68+
};
69+
let model = {};
70+
71+
beforeEach( () => {
72+
createField(schema, model);
73+
});
74+
75+
it("should give the model static value", () => {
76+
expect(field).to.be.exist;
77+
expect(field.value).to.be.equal("John Doe");
78+
});
79+
80+
it("should set new value to model if value changed", () => {
81+
field.value = "Foo Bar";
82+
expect(model.name).to.be.equal("Foo Bar");
83+
});
84+
85+
});*/
86+
87+
});

0 commit comments

Comments
 (0)