-
Notifications
You must be signed in to change notification settings - Fork 8
/
test-vue:vue.js
211 lines (191 loc) · 6.1 KB
/
test-vue:vue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
if(Meteor.isClient){
Tinytest.add('Vue can be initalized', function (test) {
test.isNotNull(Vue, 'Vue should exist');
test.isTrue(typeof(Vue) === "function", 'vue should be a function');
var vm = new Vue();
test.isTrue(typeof(vm.$sync) === "function", 'nprogres sync should be a function');
test.isTrue(typeof(vm.$unsync) === "function", 'nprogres unsync should be a function');
});
Tinytest.addAsync('Vue supports binding to the vm, `this` refer to the vm itself', function (test, next) {
var vm = new Vue({
data: {
a: 'key'
},
computed: {
c: function(){
return this.b;
}
},
sync: {
b: function(){
return Session.get(this.a);
}
}
});
Session.set('key', 'iamb');
_.delay(function(){
test.equal(Session.get('key'), vm.b);
test.equal(Session.get('key'), vm.c);
next();
}, 0);
});
Tinytest.addAsync('Vue can be synced with Session', function (test, next) {
var vm = new Vue({
data: {
a: 1
},
computed: {
c: function(){
return this.b
}
},
sync: {
b: function(){
return Session.get('b');
}
}
});
Session.set('b', 'iamb');
_.delay(function(){
test.equal(Session.get('b'), vm.b);
test.equal(Session.get('b'), vm.c);
next();
}, 0);
});
Tinytest.addAsync('Vue can be synced with Collections find().fetch()', function (test, next) {
var C = new Mongo.Collection(null);
var vm = new Vue({
computed: {
c: function(){
return this.b;
}
},
sync: {
b: function(){
return C.find('b').fetch();
}
}
});
C.insert({_id: 'b', title: 'B'}, function(){
_.delay(function(){
var d = C.find('b').fetch();
test.equal(d[0], vm.b[0]);
test.equal(d[0], vm.c[0]);
C.update('b', {$set: {title: 'BB'}}, function(){
_.delay(function(){
var d = C.find('b').fetch();
test.equal(d[0], vm.b[0]);
test.equal(d[0], vm.c[0]);
next();
}, 0);
});
}, 0);
});
});
Tinytest.addAsync('Vue can be synced with Collections find()', function (test, next) {
var C = new Mongo.Collection(null);
var vm = new Vue({
computed: {
c: function(){
return this.b;
}
},
sync: {
b: function(){
return C.find('b');
}
}
});
C.insert({_id: 'b', title: 'B'}, function(){
_.delay(function(){
var d = C.find('b').fetch();
test.equal(d[0], vm.b[0]);
test.equal(d[0], vm.c[0]);
C.update('b', {$set: {title: 'BB'}}, function(){
_.delay(function(){
var d = C.find('b').fetch();
test.equal(d[0], vm.b[0]);
test.equal(d[0], vm.c[0]);
next();
}, 0);
});
}, 0);
});
});
Tinytest.addAsync('Vue can be synced with Collections findOne()', function (test, next) {
var C = new Mongo.Collection(null);
var vm = new Vue({
computed: {
c: function(){
return this.b;
}
},
sync: {
b: function(){
return C.findOne('b');
}
}
});
C.insert({_id: 'b', title: 'ZZ'}, function(){
_.delay(function(){
var d = C.findOne('b');
test.equal(d, vm.b);
test.equal(d, vm.c);
next();
}, 0);
});
});
Tinytest.addAsync('Components support the sync option', function (test, next) {
var C = new Mongo.Collection(null);
var TestComponent = Vue.extend({
sync: {
b: function(){
return C.findOne('item1');
}
}
});
Vue.component('test', TestComponent);
var vm = new TestComponent({
sync: {
c: function() {
return C.findOne('item2');
}
},
});
var count = 3;
C.insert({_id: 'item1', title: 'ZZ'}, function(){
_.delay(function(){
var d = C.findOne('item1');
test.equal(d, vm.b, "Sync option in Vue.extend");
count--;
if (count == 0)
next();
}, 0);
});
C.insert({_id: 'item2', title: 'ZZ'}, function(){
_.delay(function(){
var d = C.findOne('item2');
test.equal(d, vm.c, "Sync option in component constructor");
count--;
if (count == 0)
next();
}, 0);
});
var vm2 = new TestComponent({
sync: {
b: function() {
return C.findOne('item3');
}
}
});
C.insert({_id: 'item3', title: 'ZZ'}, function(){
_.delay(function(){
var d = C.findOne('item3');
test.equal(d, vm2.b, "Sync option overrides correctly");
count--;
if (count == 0)
next();
}, 0);
});
});
}