@@ -49,14 +49,7 @@ function queryTest(observable: Observable<any>, subject: Subject<any>, done: any
4949}
5050
5151describe ( 'FirebaseListFactory' , ( ) => {
52- var subscription : Subscription ;
53- var questions : FirebaseListObservable < any > ;
54- var questionsSnapshotted : FirebaseListObservable < any > ;
55- var ref : any ;
56- var refSnapshotted : any ;
57- var val1 : any ;
58- var val2 : any ;
59- var val3 : any ;
52+
6053 var app : firebase . app . App ;
6154
6255 beforeEach ( ( ) => {
@@ -351,13 +344,22 @@ describe('FirebaseListFactory', () => {
351344 expect ( observable . update instanceof Function ) . toBe ( true ) ;
352345 expect ( observable . remove instanceof Function ) . toBe ( true ) ;
353346 } ) ;
354-
355-
356347 } ) ;
357348
358349 describe ( 'methods' , ( ) => {
359350
351+ var toKey ;
352+ var val1 : any ;
353+ var val2 : any ;
354+ var val3 : any ;
355+ var questions : FirebaseListObservable < any > ;
356+ var questionsSnapshotted : FirebaseListObservable < any > ;
357+ var ref : any ;
358+ var refSnapshotted : any ;
359+ var subscription : Subscription ;
360+
360361 beforeEach ( ( done : any ) => {
362+ toKey = ( val ) => val . key ;
361363 val1 = { key : 'key1' } ;
362364 val2 = { key : 'key2' } ;
363365 val3 = { key : 'key3' } ;
@@ -368,6 +370,7 @@ describe('FirebaseListFactory', () => {
368370 refSnapshotted = questionsSnapshotted . $ref ;
369371 } ) ;
370372
373+
371374 afterEach ( ( done : any ) => {
372375 if ( subscription && ! subscription . closed ) {
373376 subscription . unsubscribe ( ) ;
@@ -434,6 +437,46 @@ describe('FirebaseListFactory', () => {
434437 } ) ;
435438
436439
440+ it ( 'should re-emit identical instances of unchanged children' , ( done : any ) => {
441+
442+ let prev ;
443+
444+ take . call ( questions , 2 ) . subscribe (
445+ ( list ) => {
446+ if ( prev ) {
447+ expect ( list [ 0 ] ) . toBe ( prev [ 0 ] ) ;
448+ done ( ) ;
449+ } else {
450+ prev = list ;
451+ questions . push ( { name : 'bob' } ) ;
452+ }
453+ } ,
454+ done . fail
455+ ) ;
456+ questions . push ( { name : 'alice' } ) ;
457+ } ) ;
458+
459+
460+ it ( 'should re-emit identical instances of unchanged children as snapshots' , ( done : any ) => {
461+
462+ let prev ;
463+
464+ take . call ( questionsSnapshotted , 2 ) . subscribe (
465+ ( list ) => {
466+ if ( prev ) {
467+ expect ( list [ 0 ] ) . toBe ( prev [ 0 ] ) ;
468+ done ( ) ;
469+ } else {
470+ prev = list ;
471+ questionsSnapshotted . push ( { name : 'bob' } ) ;
472+ }
473+ } ,
474+ done . fail
475+ ) ;
476+ questionsSnapshotted . push ( { name : 'alice' } ) ;
477+ } ) ;
478+
479+
437480 it ( 'should call off on all events when disposed' , ( done : any ) => {
438481 const questionRef = firebase . database ( ) . ref ( ) . child ( 'questions' ) ;
439482 var firebaseSpy = spyOn ( questionRef , 'off' ) . and . callThrough ( ) ;
@@ -447,65 +490,57 @@ describe('FirebaseListFactory', () => {
447490
448491
449492 describe ( 'onChildAdded' , ( ) => {
493+
450494 it ( 'should add the child after the prevKey' , ( ) => {
451- expect ( onChildAdded ( [ val1 , val2 ] , val3 , 'key1' ) ) . toEqual ( [ val1 , val3 , val2 ] ) ;
495+ expect ( onChildAdded ( [ val1 , val2 ] , val3 , toKey , 'key1' ) ) . toEqual ( [ val1 , val3 , val2 ] ) ;
452496 } ) ;
453497
454498
455499 it ( 'should not mutate the input array' , ( ) => {
456500 var inputArr = [ val1 ] ;
457- expect ( onChildAdded ( inputArr , val2 , 'key1' ) ) . not . toEqual ( inputArr ) ;
501+ expect ( onChildAdded ( inputArr , val2 , toKey , 'key1' ) ) . not . toEqual ( inputArr ) ;
458502 } ) ;
459503 } ) ;
460504
461505
462506 describe ( 'onChildChanged' , ( ) => {
507+
463508 it ( 'should move the child after the specified prevKey' , ( ) => {
464- expect ( onChildChanged ( [ val1 , val2 ] , val1 , 'key2' ) ) . toEqual ( [ val2 , val1 ] ) ;
509+ expect ( onChildChanged ( [ val1 , val2 ] , val1 , toKey , 'key2' ) ) . toEqual ( [ val2 , val1 ] ) ;
465510 } ) ;
466511
467512
468513 it ( 'should move the child to the beginning if prevKey is null' , ( ) => {
469514 expect (
470- onChildChanged ( [ val1 , val2 , val3 ] , val2 , null )
515+ onChildChanged ( [ val1 , val2 , val3 ] , val2 , toKey , null )
471516 ) . toEqual ( [ val2 , val1 , val3 ] ) ;
472517 } ) ;
473518
474519 it ( 'should not duplicate the first item if it is the one that changed' , ( ) => {
475520 expect (
476- onChildChanged ( [ val1 , val2 , val3 ] , val1 , null )
521+ onChildChanged ( [ val1 , val2 , val3 ] , val1 , toKey , null )
477522 ) . not . toEqual ( [ val1 , val1 , val2 , val3 ] ) ;
478523 } ) ;
479524
480525 it ( 'should not mutate the input array' , ( ) => {
481526 var inputArr = [ val1 , val2 ] ;
482- expect ( onChildChanged ( inputArr , val1 , 'key2' ) ) . not . toEqual ( inputArr ) ;
527+ expect ( onChildChanged ( inputArr , val1 , toKey , 'key2' ) ) . not . toEqual ( inputArr ) ;
483528 } ) ;
484529
485530
486531 it ( 'should update the child' , ( ) => {
487532 expect (
488- onChildUpdated ( [ val1 , val2 , val3 ] , { key : 'newkey' } , 'key1' ) . map ( v => v . key )
533+ onChildUpdated ( [ val1 , val2 , val3 ] , { key : 'newkey' } , toKey , 'key1' ) . map ( v => v . key )
489534 ) . toEqual ( [ 'key1' , 'newkey' , 'key3' ] ) ;
490535 } ) ;
491536 } ) ;
492537
493538
494539 describe ( 'onChildRemoved' , ( ) => {
495- var val1 : any ;
496- var val2 : any ;
497- var val3 : any ;
498-
499- beforeEach ( ( ) => {
500- val1 = { key : ( ) => 'key1' } ;
501- val2 = { key : ( ) => 'key2' } ;
502- val3 = { key : ( ) => 'key3' } ;
503- } ) ;
504-
505540
506541 it ( 'should remove the child' , ( ) => {
507542 expect (
508- onChildRemoved ( [ val1 , val2 , val3 ] , val2 )
543+ onChildRemoved ( [ val1 , val2 , val3 ] , val2 , toKey )
509544 ) . toEqual ( [ val1 , val3 ] ) ;
510545 } ) ;
511546 } ) ;
0 commit comments