@@ -447,7 +447,7 @@ describe('ReactFire', function() {
447447 shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
448448 } ) ;
449449
450- it ( 'moves an array record when it\'s order changes (moved to start of array)' , function ( done ) {
450+ it ( 'moves an array record when it\'s order changes (moved to start of array) [orderByValue()] ' , function ( done ) {
451451 var TestComponent = React . createClass ( {
452452 mixins : [ ReactFireMixin ] ,
453453
@@ -476,7 +476,7 @@ describe('ReactFire', function() {
476476 shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
477477 } ) ;
478478
479- it ( 'moves an array record when it\'s order changes (moved to middle of array)' , function ( done ) {
479+ it ( 'moves an array record when it\'s order changes (moved to middle of array) [orderByValue()] ' , function ( done ) {
480480 var TestComponent = React . createClass ( {
481481 mixins : [ ReactFireMixin ] ,
482482
@@ -505,7 +505,7 @@ describe('ReactFire', function() {
505505 shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
506506 } ) ;
507507
508- it ( 'moves an array record when it\'s order changes (moved to end of array)' , function ( done ) {
508+ it ( 'moves an array record when it\'s order changes (moved to end of array) [orderByValue()] ' , function ( done ) {
509509 var TestComponent = React . createClass ( {
510510 mixins : [ ReactFireMixin ] ,
511511
@@ -533,6 +533,124 @@ describe('ReactFire', function() {
533533
534534 shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
535535 } ) ;
536+
537+ it ( 'moves an array record when it\'s order changes (moved to start of array) [orderByChild()]' , function ( done ) {
538+ var TestComponent = React . createClass ( {
539+ mixins : [ ReactFireMixin ] ,
540+
541+ componentWillMount : function ( ) {
542+ this . bindAsArray ( firebaseRef . orderByChild ( 'value' ) , 'items' ) ;
543+
544+ var _this = this ;
545+ firebaseRef . set ( { a : { value : 2 } , b : { value : 3 } , c : { value : 2 } } , function ( ) {
546+ firebaseRef . child ( 'b' ) . set ( { value : 1 } , function ( ) {
547+ expect ( _this . state . items ) . to . deep . equal ( [
548+ { '.key' : 'b' , value : 1 } ,
549+ { '.key' : 'a' , value : 2 } ,
550+ { '.key' : 'c' , value : 2 }
551+ ] ) ;
552+
553+ done ( ) ;
554+ } ) ;
555+ } ) ;
556+ } ,
557+
558+ render : function ( ) {
559+ return React . DOM . div ( null ) ;
560+ }
561+ } ) ;
562+
563+ shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
564+ } ) ;
565+
566+ it ( 'moves an array record when it\'s order changes (moved to middle of array) [orderByChild()]' , function ( done ) {
567+ var TestComponent = React . createClass ( {
568+ mixins : [ ReactFireMixin ] ,
569+
570+ componentWillMount : function ( ) {
571+ this . bindAsArray ( firebaseRef . orderByChild ( 'value' ) , 'items' ) ;
572+
573+ var _this = this ;
574+ firebaseRef . set ( { a : { value : 2 } , b : { value : 1 } , c : { value : 4 } } , function ( ) {
575+ firebaseRef . child ( 'b' ) . set ( { value : 3 } , function ( ) {
576+ expect ( _this . state . items ) . to . deep . equal ( [
577+ { '.key' : 'a' , value : 2 } ,
578+ { '.key' : 'b' , value : 3 } ,
579+ { '.key' : 'c' , value : 4 }
580+ ] ) ;
581+
582+ done ( ) ;
583+ } ) ;
584+ } ) ;
585+ } ,
586+
587+ render : function ( ) {
588+ return React . DOM . div ( null ) ;
589+ }
590+ } ) ;
591+
592+ shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
593+ } ) ;
594+
595+ it ( 'moves an array record when it\'s order changes (moved to end of array) [orderByChild()]' , function ( done ) {
596+ var TestComponent = React . createClass ( {
597+ mixins : [ ReactFireMixin ] ,
598+
599+ componentWillMount : function ( ) {
600+ this . bindAsArray ( firebaseRef . orderByChild ( 'value' ) , 'items' ) ;
601+
602+ var _this = this ;
603+ firebaseRef . set ( { a : { value : 2 } , b : { value : 1 } , c : { value : 3 } } , function ( ) {
604+ firebaseRef . child ( 'b' ) . set ( { value : 4 } , function ( ) {
605+ expect ( _this . state . items ) . to . deep . equal ( [
606+ { '.key' : 'a' , value : 2 } ,
607+ { '.key' : 'c' , value : 3 } ,
608+ { '.key' : 'b' , value : 4 }
609+ ] ) ;
610+
611+ done ( ) ;
612+ } ) ;
613+ } ) ;
614+ } ,
615+
616+ render : function ( ) {
617+ return React . DOM . div ( null ) ;
618+ }
619+ } ) ;
620+
621+ shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
622+ } ) ;
623+
624+ it ( 'works with orderByKey() queries' , function ( done ) {
625+ var TestComponent = React . createClass ( {
626+ mixins : [ ReactFireMixin ] ,
627+
628+ componentWillMount : function ( ) {
629+ this . bindAsArray ( firebaseRef . orderByKey ( ) , 'items' ) ;
630+
631+ var _this = this ;
632+ firebaseRef . set ( { b : 2 , c : 1 , d : 3 } , function ( ) {
633+ firebaseRef . update ( { a : 4 , d : 4 , e : 0 } , function ( ) {
634+ expect ( _this . state . items ) . to . deep . equal ( [
635+ { '.key' : 'a' , '.value' : 4 } ,
636+ { '.key' : 'b' , '.value' : 2 } ,
637+ { '.key' : 'c' , '.value' : 1 } ,
638+ { '.key' : 'd' , '.value' : 4 } ,
639+ { '.key' : 'e' , '.value' : 0 }
640+ ] ) ;
641+
642+ done ( ) ;
643+ } ) ;
644+ } ) ;
645+ } ,
646+
647+ render : function ( ) {
648+ return React . DOM . div ( null ) ;
649+ }
650+ } ) ;
651+
652+ shallowRenderer . render ( React . createElement ( TestComponent ) ) ;
653+ } ) ;
536654 } ) ;
537655
538656
0 commit comments