@@ -210,4 +210,254 @@ describe('VueFire', function () {
210
210
} )
211
211
} )
212
212
} )
213
+
214
+ it ( 'binds multiple Firebase references to state variables at the same time' , function ( done ) {
215
+ var vm = new Vue ( {
216
+ firebase : {
217
+ bindVar0 : firebaseRef . child ( 'items0' ) ,
218
+ bindVar1 : firebaseRef . child ( 'items1' )
219
+ } ,
220
+ template :
221
+ '<div>' +
222
+ '<div v-for="item in bindVar0">{{ item[".key"] }} {{ item.index }} </div>' +
223
+ '<div v-for="item in bindVar1">{{ item[".key"] }} {{ item[".value"] }} </div>' +
224
+ '</div>'
225
+ } ) . $mount ( )
226
+ firebaseRef . set ( {
227
+ items0 : {
228
+ first : { index : 0 } ,
229
+ second : { index : 1 } ,
230
+ third : { index : 2 }
231
+ } ,
232
+ items1 : [ 'first' , 'second' , 'third' ]
233
+ } , function ( ) {
234
+ expect ( vm . bindVar0 ) . to . deep . equal ( [
235
+ { '.key' : 'first' , index : 0 } ,
236
+ { '.key' : 'second' , index : 1 } ,
237
+ { '.key' : 'third' , index : 2 }
238
+ ] )
239
+
240
+ expect ( vm . bindVar1 ) . to . deep . equal ( [
241
+ { '.key' : '0' , '.value' : 'first' } ,
242
+ { '.key' : '1' , '.value' : 'second' } ,
243
+ { '.key' : '2' , '.value' : 'third' }
244
+ ] )
245
+ Vue . nextTick ( function ( ) {
246
+ expect ( vm . $el . textContent ) . to . contain ( 'first 0 second 1 third 2' )
247
+ expect ( vm . $el . textContent ) . to . contain ( '0 first 1 second 2 third' )
248
+ done ( )
249
+ } )
250
+ } )
251
+ } )
252
+
253
+ it ( 'updates an array record when its value changes' , function ( done ) {
254
+ var vm = new Vue ( {
255
+ firebase : {
256
+ items : firebaseRef
257
+ } ,
258
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] || item.foo }} </div></div>'
259
+ } ) . $mount ( )
260
+ firebaseRef . set ( { a : 1 , b : 2 , c : 3 } , function ( ) {
261
+ firebaseRef . child ( 'b' ) . set ( { foo : 'bar' } , function ( ) {
262
+ expect ( vm . items ) . to . deep . equal ( [
263
+ { '.key' : 'a' , '.value' : 1 } ,
264
+ { '.key' : 'b' , foo : 'bar' } ,
265
+ { '.key' : 'c' , '.value' : 3 }
266
+ ] )
267
+ Vue . nextTick ( function ( ) {
268
+ expect ( vm . $el . textContent ) . to . contain ( 'a 1 b bar c 3' )
269
+ done ( )
270
+ } )
271
+ } )
272
+ } )
273
+ } )
274
+
275
+ it ( 'removes an array record when it is deleted' , function ( done ) {
276
+ var vm = new Vue ( {
277
+ firebase : {
278
+ items : firebaseRef
279
+ } ,
280
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
281
+ } ) . $mount ( )
282
+ firebaseRef . set ( { a : 1 , b : 2 , c : 3 } , function ( ) {
283
+ firebaseRef . child ( 'b' ) . remove ( function ( ) {
284
+ expect ( vm . items ) . to . deep . equal ( [
285
+ { '.key' : 'a' , '.value' : 1 } ,
286
+ { '.key' : 'c' , '.value' : 3 }
287
+ ] )
288
+ Vue . nextTick ( function ( ) {
289
+ expect ( vm . $el . textContent ) . to . contain ( 'a 1 c 3' )
290
+ done ( )
291
+ } )
292
+ } )
293
+ } )
294
+ } )
295
+
296
+ it ( 'moves an array record when it\'s order changes (moved to start of array) [orderByValue()]' , function ( done ) {
297
+ var vm = new Vue ( {
298
+ firebase : {
299
+ items : firebaseRef . orderByValue ( )
300
+ } ,
301
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
302
+ } ) . $mount ( )
303
+ firebaseRef . set ( { a : 2 , b : 3 , c : 2 } , function ( ) {
304
+ firebaseRef . child ( 'b' ) . set ( 1 , function ( ) {
305
+ expect ( vm . items ) . to . deep . equal ( [
306
+ { '.key' : 'b' , '.value' : 1 } ,
307
+ { '.key' : 'a' , '.value' : 2 } ,
308
+ { '.key' : 'c' , '.value' : 2 }
309
+ ] )
310
+ Vue . nextTick ( function ( ) {
311
+ expect ( vm . $el . textContent ) . to . contain ( 'b 1 a 2 c 2' )
312
+ done ( )
313
+ } )
314
+ } )
315
+ } )
316
+ } )
317
+
318
+ it ( 'moves an array record when it\'s order changes (moved to middle of array) [orderByValue()]' , function ( done ) {
319
+ var vm = new Vue ( {
320
+ firebase : {
321
+ items : firebaseRef . orderByValue ( )
322
+ } ,
323
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
324
+ } ) . $mount ( )
325
+ firebaseRef . set ( { a : 2 , b : 1 , c : 4 } , function ( ) {
326
+ firebaseRef . child ( 'b' ) . set ( 3 , function ( ) {
327
+ expect ( vm . items ) . to . deep . equal ( [
328
+ { '.key' : 'a' , '.value' : 2 } ,
329
+ { '.key' : 'b' , '.value' : 3 } ,
330
+ { '.key' : 'c' , '.value' : 4 }
331
+ ] )
332
+ Vue . nextTick ( function ( ) {
333
+ expect ( vm . $el . textContent ) . to . contain ( 'a 2 b 3 c 4' )
334
+ done ( )
335
+ } )
336
+ } )
337
+ } )
338
+ } )
339
+
340
+ it ( 'moves an array record when it\'s order changes (moved to end of array) [orderByValue()]' , function ( done ) {
341
+ var vm = new Vue ( {
342
+ firebase : {
343
+ items : firebaseRef . orderByValue ( )
344
+ } ,
345
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
346
+ } ) . $mount ( )
347
+ firebaseRef . set ( { a : 2 , b : 1 , c : 3 } , function ( ) {
348
+ firebaseRef . child ( 'b' ) . set ( 4 , function ( ) {
349
+ expect ( vm . items ) . to . deep . equal ( [
350
+ { '.key' : 'a' , '.value' : 2 } ,
351
+ { '.key' : 'c' , '.value' : 3 } ,
352
+ { '.key' : 'b' , '.value' : 4 }
353
+ ] )
354
+ Vue . nextTick ( function ( ) {
355
+ expect ( vm . $el . textContent ) . to . contain ( 'a 2 c 3 b 4' )
356
+ done ( )
357
+ } )
358
+ } )
359
+ } )
360
+ } )
361
+
362
+ it ( 'moves an array record when it\'s order changes (moved to start of array) [orderByChild()]' , function ( done ) {
363
+ var vm = new Vue ( {
364
+ firebase : {
365
+ items : firebaseRef . orderByChild ( 'value' )
366
+ } ,
367
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item.value }} </div></div>'
368
+ } ) . $mount ( )
369
+ firebaseRef . set ( {
370
+ a : { value : 2 } ,
371
+ b : { value : 3 } ,
372
+ c : { value : 2 }
373
+ } , function ( ) {
374
+ firebaseRef . child ( 'b' ) . set ( { value : 1 } , function ( ) {
375
+ expect ( vm . items ) . to . deep . equal ( [
376
+ { '.key' : 'b' , value : 1 } ,
377
+ { '.key' : 'a' , value : 2 } ,
378
+ { '.key' : 'c' , value : 2 }
379
+ ] )
380
+ Vue . nextTick ( function ( ) {
381
+ expect ( vm . $el . textContent ) . to . contain ( 'b 1 a 2 c 2' )
382
+ done ( )
383
+ } )
384
+ } )
385
+ } )
386
+ } )
387
+
388
+ it ( 'moves an array record when it\'s order changes (moved to middle of array) [orderByChild()]' , function ( done ) {
389
+ var vm = new Vue ( {
390
+ firebase : {
391
+ items : firebaseRef . orderByChild ( 'value' )
392
+ } ,
393
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item.value }} </div></div>'
394
+ } ) . $mount ( )
395
+ firebaseRef . set ( {
396
+ a : { value : 2 } ,
397
+ b : { value : 1 } ,
398
+ c : { value : 4 }
399
+ } , function ( ) {
400
+ firebaseRef . child ( 'b' ) . set ( { value : 3 } , function ( ) {
401
+ expect ( vm . items ) . to . deep . equal ( [
402
+ { '.key' : 'a' , value : 2 } ,
403
+ { '.key' : 'b' , value : 3 } ,
404
+ { '.key' : 'c' , value : 4 }
405
+ ] )
406
+ Vue . nextTick ( function ( ) {
407
+ expect ( vm . $el . textContent ) . to . contain ( 'a 2 b 3 c 4' )
408
+ done ( )
409
+ } )
410
+ } )
411
+ } )
412
+ } )
413
+
414
+ it ( 'moves an array record when it\'s order changes (moved to end of array) [orderByChild()]' , function ( done ) {
415
+ var vm = new Vue ( {
416
+ firebase : {
417
+ items : firebaseRef . orderByChild ( 'value' )
418
+ } ,
419
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item.value }} </div></div>'
420
+ } ) . $mount ( )
421
+ firebaseRef . set ( {
422
+ a : { value : 2 } ,
423
+ b : { value : 1 } ,
424
+ c : { value : 3 }
425
+ } , function ( ) {
426
+ firebaseRef . child ( 'b' ) . set ( { value : 4 } , function ( ) {
427
+ expect ( vm . items ) . to . deep . equal ( [
428
+ { '.key' : 'a' , value : 2 } ,
429
+ { '.key' : 'c' , value : 3 } ,
430
+ { '.key' : 'b' , value : 4 }
431
+ ] )
432
+ Vue . nextTick ( function ( ) {
433
+ expect ( vm . $el . textContent ) . to . contain ( 'a 2 c 3 b 4' )
434
+ done ( )
435
+ } )
436
+ } )
437
+ } )
438
+ } )
439
+
440
+ it ( 'works with orderByKey() queries' , function ( done ) {
441
+ var vm = new Vue ( {
442
+ firebase : {
443
+ items : firebaseRef . orderByKey ( )
444
+ } ,
445
+ template : '<div><div v-for="item in items">{{ item[".key"] }} {{ item[".value"] }} </div></div>'
446
+ } ) . $mount ( )
447
+ firebaseRef . set ( { b : 2 , c : 1 , d : 3 } , function ( ) {
448
+ firebaseRef . update ( { a : 4 , d : 4 , e : 0 } , function ( ) {
449
+ expect ( vm . items ) . to . deep . equal ( [
450
+ { '.key' : 'a' , '.value' : 4 } ,
451
+ { '.key' : 'b' , '.value' : 2 } ,
452
+ { '.key' : 'c' , '.value' : 1 } ,
453
+ { '.key' : 'd' , '.value' : 4 } ,
454
+ { '.key' : 'e' , '.value' : 0 }
455
+ ] )
456
+ Vue . nextTick ( function ( ) {
457
+ expect ( vm . $el . textContent ) . to . contain ( 'a 4 b 2 c 1 d 4 e 0' )
458
+ done ( )
459
+ } )
460
+ } )
461
+ } )
462
+ } )
213
463
} )
0 commit comments