@@ -22,7 +22,192 @@ describe('VueFire', function () {
22
22
} )
23
23
} )
24
24
25
- it ( 'should pass' , function ( ) {
26
- expect ( 1 ) . to . equal ( 1 )
25
+ it ( 'throws error for invalid firebase ref' , function ( ) {
26
+ helpers . invalidFirebaseRefs . forEach ( function ( ref ) {
27
+ expect ( function ( ) {
28
+ new Vue ( {
29
+ firebase : {
30
+ items : ref
31
+ }
32
+ } )
33
+ } ) . to . throw ( 'VueFire: invalid Firebase binding source.' )
34
+ } )
35
+ } )
36
+
37
+ it ( 'binds array records which are objects' , function ( done ) {
38
+ var vm = new Vue ( {
39
+ firebase : {
40
+ items : firebaseRef
41
+ } ,
42
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item.index }} </div></div>'
43
+ } ) . $mount ( )
44
+ firebaseRef . set ( {
45
+ first : { index : 0 } ,
46
+ second : { index : 1 } ,
47
+ third : { index : 2 }
48
+ } , function ( ) {
49
+ expect ( vm . items ) . to . deep . equal ( [
50
+ { '.key' : 'first' , index : 0 } ,
51
+ { '.key' : 'second' , index : 1 } ,
52
+ { '.key' : 'third' , index : 2 }
53
+ ] )
54
+ Vue . nextTick ( function ( ) {
55
+ expect ( vm . $el . textContent ) . to . contain ( 'first 0 second 1 third 2' )
56
+ done ( )
57
+ } )
58
+ } )
59
+ } )
60
+
61
+ it ( 'binds array records which are primitives' , function ( done ) {
62
+ var vm = new Vue ( {
63
+ firebase : {
64
+ items : firebaseRef
65
+ } ,
66
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
67
+ } ) . $mount ( )
68
+ firebaseRef . set ( [ 'first' , 'second' , 'third' ] , function ( ) {
69
+ expect ( vm . items ) . to . deep . equal ( [
70
+ { '.key' : '0' , '.value' : 'first' } ,
71
+ { '.key' : '1' , '.value' : 'second' } ,
72
+ { '.key' : '2' , '.value' : 'third' }
73
+ ] )
74
+ Vue . nextTick ( function ( ) {
75
+ expect ( vm . $el . textContent ) . to . contain ( '0 first 1 second 2 third' )
76
+ done ( )
77
+ } )
78
+ } )
79
+ } )
80
+
81
+ it ( 'binds array records which are a mix of objects and primitives' , function ( done ) {
82
+ var vm = new Vue ( {
83
+ firebase : {
84
+ items : firebaseRef
85
+ } ,
86
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} {{ item.index}}</div></div>'
87
+ } ) . $mount ( )
88
+ firebaseRef . set ( {
89
+ 0 : 'first' ,
90
+ 1 : 'second' ,
91
+ third : { index : 2 }
92
+ } , function ( ) {
93
+ expect ( vm . items ) . to . deep . equal ( [
94
+ { '.key' : '0' , '.value' : 'first' } ,
95
+ { '.key' : '1' , '.value' : 'second' } ,
96
+ { '.key' : 'third' , index : 2 }
97
+ ] )
98
+ Vue . nextTick ( function ( ) {
99
+ expect ( vm . $el . textContent ) . to . contain ( '0 first 1 second third 2' )
100
+ done ( )
101
+ } )
102
+ } )
103
+ } )
104
+
105
+ it ( 'binds array records which are a mix of objects and primitives' , function ( done ) {
106
+ var vm = new Vue ( {
107
+ firebase : {
108
+ items : firebaseRef
109
+ }
110
+ } )
111
+ firebaseRef . set ( null , function ( ) {
112
+ expect ( vm . items ) . to . deep . equal ( [ ] )
113
+ done ( )
114
+ } )
115
+ } )
116
+
117
+ it ( 'binds sparse arrays' , function ( done ) {
118
+ var vm = new Vue ( {
119
+ firebase : {
120
+ items : firebaseRef
121
+ }
122
+ } )
123
+ firebaseRef . set ( { 0 : 'a' , 2 : 'b' , 5 : 'c' } , function ( ) {
124
+ expect ( vm . items ) . to . deep . equal ( [
125
+ { '.key' : '0' , '.value' : 'a' } ,
126
+ { '.key' : '2' , '.value' : 'b' } ,
127
+ { '.key' : '5' , '.value' : 'c' }
128
+ ] )
129
+ done ( )
130
+ } )
131
+ } )
132
+
133
+ it ( 'binds only a subset of records when using limit queries' , function ( done ) {
134
+ var vm = new Vue ( {
135
+ firebase : {
136
+ items : firebaseRef . limitToLast ( 2 )
137
+ } ,
138
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
139
+ } ) . $mount ( )
140
+ firebaseRef . set ( { a : 1 , b : 2 , c : 3 } , function ( ) {
141
+ expect ( vm . items ) . to . deep . equal ( [
142
+ { '.key' : 'b' , '.value' : 2 } ,
143
+ { '.key' : 'c' , '.value' : 3 }
144
+ ] )
145
+ Vue . nextTick ( function ( ) {
146
+ expect ( vm . $el . textContent ) . to . contain ( 'b 2 c 3' )
147
+ done ( )
148
+ } )
149
+ } )
150
+ } )
151
+
152
+ it ( 'removes records when they fall outside of a limit query' , function ( done ) {
153
+ var vm = new Vue ( {
154
+ firebase : {
155
+ items : firebaseRef . limitToLast ( 2 )
156
+ } ,
157
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
158
+ } ) . $mount ( )
159
+ firebaseRef . set ( { a : 1 , b : 2 , c : 3 } , function ( ) {
160
+ firebaseRef . child ( 'd' ) . set ( 4 , function ( ) {
161
+ expect ( vm . items ) . to . deep . equal ( [
162
+ { '.key' : 'c' , '.value' : 3 } ,
163
+ { '.key' : 'd' , '.value' : 4 }
164
+ ] )
165
+ Vue . nextTick ( function ( ) {
166
+ expect ( vm . $el . textContent ) . to . contain ( 'c 3 d 4' )
167
+ done ( )
168
+ } )
169
+ } )
170
+ } )
171
+ } )
172
+
173
+ it ( 'adds a new record when an existing record in the limit query is removed' , function ( done ) {
174
+ var vm = new Vue ( {
175
+ firebase : {
176
+ items : firebaseRef . limitToLast ( 2 )
177
+ } ,
178
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
179
+ } ) . $mount ( )
180
+ firebaseRef . set ( { a : 1 , b : 2 , c : 3 } , function ( ) {
181
+ firebaseRef . child ( 'b' ) . remove ( function ( ) {
182
+ expect ( vm . items ) . to . deep . equal ( [
183
+ { '.key' : 'a' , '.value' : 1 } ,
184
+ { '.key' : 'c' , '.value' : 3 }
185
+ ] )
186
+ Vue . nextTick ( function ( ) {
187
+ expect ( vm . $el . textContent ) . to . contain ( 'a 1 c 3' )
188
+ done ( )
189
+ } )
190
+ } )
191
+ } )
192
+ } )
193
+
194
+ it ( 'binds records in the correct order when using ordered queries' , function ( done ) {
195
+ var vm = new Vue ( {
196
+ firebase : {
197
+ items : firebaseRef . orderByValue ( )
198
+ } ,
199
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
200
+ } ) . $mount ( )
201
+ firebaseRef . set ( { a : 2 , b : 1 , c : 3 } , function ( ) {
202
+ expect ( vm . items ) . to . deep . equal ( [
203
+ { '.key' : 'b' , '.value' : 1 } ,
204
+ { '.key' : 'a' , '.value' : 2 } ,
205
+ { '.key' : 'c' , '.value' : 3 }
206
+ ] )
207
+ Vue . nextTick ( function ( ) {
208
+ expect ( vm . $el . textContent ) . to . contain ( 'b 1 a 2 c 3' )
209
+ done ( )
210
+ } )
211
+ } )
27
212
} )
28
213
} )
0 commit comments