@@ -713,4 +713,100 @@ describe('uiScroll', function () {
713713
714714 } ) ;
715715
716+ describe ( 'topVisible property: deep access and sync' , function ( ) {
717+
718+ it ( 'should get topVisible as an adapter property' , function ( ) {
719+ runTest ( { datasource : 'myMultipageDatasource' , adapter : 'adapterContainer.innerContainer.adapter' } ,
720+ function ( viewport , scope ) {
721+ expect ( ! ! scope . adapterContainer && ! ! scope . adapterContainer . innerContainer && ! ! scope . adapterContainer . innerContainer . adapter ) . toBe ( true ) ;
722+ expect ( angular . isString ( scope . adapterContainer . innerContainer . adapter . topVisible ) ) . toBe ( true ) ;
723+ }
724+ ) ;
725+ } ) ;
726+
727+ it ( 'should get topVisible as a scope property' , function ( ) {
728+ runTest ( { datasource : 'myMultipageDatasource' , topVisible : 'scopeContainer.innerContainer.topVisible' } ,
729+ function ( viewport , scope ) {
730+ expect ( ! ! scope . scopeContainer && ! ! scope . scopeContainer . innerContainer ) . toBe ( true ) ;
731+ expect ( angular . isString ( scope . scopeContainer . innerContainer . topVisible ) ) . toBe ( true ) ;
732+ }
733+ ) ;
734+ } ) ;
735+
736+ it ( 'should sync scope-topVisible with adapter-topVisible' , function ( ) {
737+ runTest ( {
738+ datasource : 'myMultipageDatasource' ,
739+ itemHeight : 40 ,
740+ bufferSize : 3 ,
741+ adapter : 'container1.adapter' ,
742+ topVisible : 'container2.topVisible'
743+ } ,
744+ function ( viewport , scope , $timeout ) {
745+ var topVisibleChangeCount = 0 ;
746+
747+ scope . $watch ( 'container1.adapter.topVisible' , function ( newValue ) {
748+ topVisibleChangeCount ++ ;
749+
750+ expect ( scope . container1 . adapter . topVisible ) . toBe ( newValue ) ;
751+ expect ( scope . container2 . topVisible ) . toBe ( newValue ) ;
752+
753+ if ( topVisibleChangeCount === 1 ) {
754+ expect ( newValue ) . toBe ( 'item3' ) ;
755+ }
756+ else if ( topVisibleChangeCount === 2 ) {
757+ expect ( newValue ) . toBe ( 'item8' ) ;
758+ }
759+ } ) ;
760+
761+ viewport . scrollTop ( 100 ) ; // 100 : 40 = 2.5 --> item3
762+ viewport . trigger ( 'scroll' ) ;
763+ $timeout . flush ( ) ;
764+
765+ viewport . scrollTop ( 300 ) ; // 300 : 40 = 7.5 --> item8
766+ viewport . trigger ( 'scroll' ) ;
767+ $timeout . flush ( ) ;
768+
769+ expect ( topVisibleChangeCount ) . toBe ( 2 ) ;
770+ }
771+ ) ;
772+ } ) ;
773+
774+ it ( 'should sync scope-topVisible with adapter-topVisible in case of single fetch' , function ( ) {
775+ runTest ( {
776+ datasource : 'myOneBigPageDatasource' ,
777+ itemHeight : 40 ,
778+ bufferSize : 3 ,
779+ adapter : 'container1.adapter' ,
780+ topVisible : 'container2.topVisible'
781+ } ,
782+ function ( viewport , scope ) {
783+ var topVisibleChangeCount = 0 ;
784+
785+ scope . $watch ( 'container1.adapter.topVisible' , function ( newValue ) {
786+ topVisibleChangeCount ++ ;
787+
788+ expect ( scope . container1 . adapter . topVisible ) . toBe ( newValue ) ;
789+ expect ( scope . container2 . topVisible ) . toBe ( newValue ) ;
790+
791+ if ( topVisibleChangeCount === 1 ) {
792+ expect ( newValue ) . toBe ( 'item3' ) ;
793+ }
794+ else if ( topVisibleChangeCount === 2 ) {
795+ expect ( newValue ) . toBe ( 'item8' ) ;
796+ }
797+ } ) ;
798+
799+ viewport . scrollTop ( 100 ) ; // 100 : 40 = 2.5 --> item3
800+ viewport . trigger ( 'scroll' ) ;
801+
802+ viewport . scrollTop ( 300 ) ; // 300 : 40 = 7.5 --> item8
803+ viewport . trigger ( 'scroll' ) ;
804+
805+ expect ( topVisibleChangeCount ) . toBe ( 2 ) ;
806+ }
807+ ) ;
808+ } ) ;
809+
810+ } ) ;
811+
716812} ) ;
0 commit comments