@@ -1611,42 +1611,48 @@ describe('uiScroll', function () {
1611
1611
} ) ;
1612
1612
1613
1613
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
+ } ;
1615
1623
1616
1624
injectDatasource ( 'myEdgeDatasource' ) ;
1617
1625
1618
- var cleanBuffer = function ( scope ) {
1626
+ var cleanBuffer = function ( datasource , scope , applyUpdateOptions ) {
1619
1627
var get = datasource . get ;
1620
1628
var removedItems = [ ] ;
1629
+ var first = - 5 ;
1621
1630
// sync the datasource
1622
1631
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 ) ;
1629
1638
} ;
1630
1639
// 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 ) ;
1639
1644
} ;
1640
1645
1641
- it ( 'should be consistent on forward direction with immutabeTop' , function ( ) {
1646
+ it ( 'should be consistent on forward direction when eof with immutabeTop' , function ( ) {
1642
1647
runTest ( scrollSettings ,
1643
1648
function ( viewport , scope ) {
1644
1649
expect ( scope . adapter . isBOF ( ) ) . toBe ( false ) ;
1645
1650
expect ( scope . adapter . isEOF ( ) ) . toBe ( true ) ;
1646
1651
1647
1652
// remove items 0..6 items form -5..6 datasource
1648
- cleanBuffer ( scope ) ;
1653
+ cleanBuffer ( datasource , scope , { immutableTop : true } ) ;
1649
1654
1655
+ // result [-5..-1]
1650
1656
expect ( scope . adapter . isBOF ( ) ) . toBe ( true ) ;
1651
1657
expect ( scope . adapter . isEOF ( ) ) . toBe ( true ) ;
1652
1658
expect ( scope . adapter . bufferFirst ) . toBe ( 'item-5' ) ;
@@ -1656,6 +1662,27 @@ describe('uiScroll', function () {
1656
1662
) ;
1657
1663
} ) ;
1658
1664
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
+
1659
1686
} ) ;
1660
1687
1661
1688
} ) ;
0 commit comments