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