@@ -1611,42 +1611,48 @@ describe('uiScroll', function () {
16111611 } ) ;
16121612
16131613 describe ( 'buffer cleanup' , function ( ) {
1614- var scrollSettings = { datasource : 'myEdgeDatasource' , adapter : 'adapter' , viewportHeight : 60 , itemHeight : 20 , padding : 0.3 , startIndex : 3 , bufferSize : 3 } ;
1614+ var scrollSettings = {
1615+ datasource : 'myEdgeDatasource' ,
1616+ adapter : 'adapter' ,
1617+ viewportHeight : 60 ,
1618+ itemHeight : 20 ,
1619+ padding : 0.3 ,
1620+ startIndex : 3 ,
1621+ bufferSize : 3
1622+ } ;
16151623
16161624 injectDatasource ( 'myEdgeDatasource' ) ;
16171625
1618- var cleanBuffer = function ( scope ) {
1626+ var cleanBuffer = function ( datasource , scope , applyUpdateOptions ) {
16191627 var get = datasource . get ;
16201628 var removedItems = [ ] ;
1629+ var first = - 5 ;
16211630 // sync the datasource
16221631 datasource . get = function ( index , count , success ) {
1623- get ( index , count , function ( result ) {
1624- result = result . filter ( function ( item ) {
1625- return removedItems . indexOf ( item ) === - 1 ;
1626- } ) ;
1627- success ( result ) ;
1628- } ) ;
1632+ var removedIndex = removedItems . indexOf ( 'item' + index ) ;
1633+ if ( removedIndex !== - 1 ) {
1634+ // todo consider mutable-top case
1635+ index += removedItems . length - removedIndex ;
1636+ }
1637+ get ( index , count , success ) ;
16291638 } ;
16301639 // clean up the buffer
1631- scope . adapter . applyUpdates (
1632- function ( item ) {
1633- removedItems . push ( item ) ;
1634- return [ ] ;
1635- } , {
1636- immutableTop : true
1637- }
1638- ) ;
1640+ scope . adapter . applyUpdates ( function ( item ) {
1641+ removedItems . push ( item ) ;
1642+ return [ ] ;
1643+ } , applyUpdateOptions ) ;
16391644 } ;
16401645
1641- it ( 'should be consistent on forward direction with immutabeTop' , function ( ) {
1646+ it ( 'should be consistent on forward direction when eof with immutabeTop' , function ( ) {
16421647 runTest ( scrollSettings ,
16431648 function ( viewport , scope ) {
16441649 expect ( scope . adapter . isBOF ( ) ) . toBe ( false ) ;
16451650 expect ( scope . adapter . isEOF ( ) ) . toBe ( true ) ;
16461651
16471652 // remove items 0..6 items form -5..6 datasource
1648- cleanBuffer ( scope ) ;
1653+ cleanBuffer ( datasource , scope , { immutableTop : true } ) ;
16491654
1655+ // result [-5..-1]
16501656 expect ( scope . adapter . isBOF ( ) ) . toBe ( true ) ;
16511657 expect ( scope . adapter . isEOF ( ) ) . toBe ( true ) ;
16521658 expect ( scope . adapter . bufferFirst ) . toBe ( 'item-5' ) ;
@@ -1656,6 +1662,27 @@ describe('uiScroll', function () {
16561662 ) ;
16571663 } ) ;
16581664
1665+ it ( 'should be consistent on forward direction when not eof with immutabeTop' , function ( ) {
1666+ scrollSettings . startIndex = - 1 ;
1667+ scrollSettings . viewportHeight = 40 ;
1668+ runTest ( scrollSettings ,
1669+ function ( viewport , scope ) {
1670+ expect ( scope . adapter . isBOF ( ) ) . toBe ( false ) ;
1671+ expect ( scope . adapter . isEOF ( ) ) . toBe ( false ) ;
1672+
1673+ // remove items -4..1 items form -5..6 datasource
1674+ cleanBuffer ( datasource , scope , { immutableTop : true } ) ;
1675+
1676+ // result [-5, 2, 3, 4]
1677+ expect ( scope . adapter . isBOF ( ) ) . toBe ( true ) ;
1678+ expect ( scope . adapter . isEOF ( ) ) . toBe ( false ) ;
1679+ expect ( scope . adapter . bufferFirst ) . toBe ( 'item-5' ) ;
1680+ expect ( scope . adapter . bufferLast ) . toBe ( 'item4' ) ;
1681+ expect ( scope . adapter . bufferLength ) . toBe ( 4 ) ;
1682+ }
1683+ ) ;
1684+ } ) ;
1685+
16591686 } ) ;
16601687
16611688} ) ;
0 commit comments