@@ -1611,22 +1611,23 @@ describe('uiScroll', function () {
1611
1611
} ) ;
1612
1612
1613
1613
describe ( 'buffer cleanup' , function ( ) {
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
1614
+ var getSettings = function ( ) {
1615
+ return {
1616
+ datasource : 'myEdgeDatasource' ,
1617
+ adapter : 'adapter' ,
1618
+ viewportHeight : 60 ,
1619
+ itemHeight : 20 ,
1620
+ padding : 0.3 ,
1621
+ startIndex : 3 ,
1622
+ bufferSize : 3
1623
+ } ;
1622
1624
} ;
1623
1625
1624
1626
injectDatasource ( 'myEdgeDatasource' ) ;
1625
1627
1626
- var cleanBuffer = function ( datasource , scope , applyUpdateOptions ) {
1628
+ var cleanBuffer = function ( scope , applyUpdateOptions ) {
1627
1629
var get = datasource . get ;
1628
1630
var removedItems = [ ] ;
1629
- var first = - 5 ;
1630
1631
// sync the datasource
1631
1632
datasource . get = function ( index , count , success ) {
1632
1633
var removedIndex = removedItems . indexOf ( 'item' + index ) ;
@@ -1644,13 +1645,13 @@ describe('uiScroll', function () {
1644
1645
} ;
1645
1646
1646
1647
it ( 'should be consistent on forward direction when eof with immutabeTop' , function ( ) {
1647
- runTest ( scrollSettings ,
1648
+ runTest ( getSettings ( ) ,
1648
1649
function ( viewport , scope ) {
1649
1650
expect ( scope . adapter . isBOF ( ) ) . toBe ( false ) ;
1650
1651
expect ( scope . adapter . isEOF ( ) ) . toBe ( true ) ;
1651
1652
1652
1653
// remove items 0..6 items form -5..6 datasource
1653
- cleanBuffer ( datasource , scope , { immutableTop : true } ) ;
1654
+ cleanBuffer ( scope , { immutableTop : true } ) ;
1654
1655
1655
1656
// result [-5..-1]
1656
1657
expect ( scope . adapter . isBOF ( ) ) . toBe ( true ) ;
@@ -1660,9 +1661,10 @@ describe('uiScroll', function () {
1660
1661
expect ( scope . adapter . bufferLength ) . toBe ( 5 ) ;
1661
1662
}
1662
1663
) ;
1663
- } ) ;
1664
+ } ) ;
1664
1665
1665
1666
it ( 'should be consistent on forward direction when not eof with immutabeTop' , function ( ) {
1667
+ var scrollSettings = getSettings ( ) ;
1666
1668
scrollSettings . startIndex = - 1 ;
1667
1669
scrollSettings . viewportHeight = 40 ;
1668
1670
runTest ( scrollSettings ,
@@ -1671,7 +1673,7 @@ describe('uiScroll', function () {
1671
1673
expect ( scope . adapter . isEOF ( ) ) . toBe ( false ) ;
1672
1674
1673
1675
// remove items -4..1 items form -5..6 datasource
1674
- cleanBuffer ( datasource , scope , { immutableTop : true } ) ;
1676
+ cleanBuffer ( scope , { immutableTop : true } ) ;
1675
1677
1676
1678
// result [-5, 2, 3, 4]
1677
1679
expect ( scope . adapter . isBOF ( ) ) . toBe ( true ) ;
@@ -1683,6 +1685,27 @@ describe('uiScroll', function () {
1683
1685
) ;
1684
1686
} ) ;
1685
1687
1688
+ it ( 'should be consistent on backward direction when bof without immutableTop' , function ( ) {
1689
+ var scrollSettings = getSettings ( ) ;
1690
+ scrollSettings . startIndex = - 3 ;
1691
+ scrollSettings . padding = 0.5 ;
1692
+ runTest ( scrollSettings ,
1693
+ function ( viewport , scope ) {
1694
+ expect ( scope . adapter . isBOF ( ) ) . toBe ( true ) ;
1695
+ expect ( scope . adapter . isEOF ( ) ) . toBe ( false ) ;
1696
+
1697
+ // remove items -5..1 items form -5..6 datasource
1698
+ cleanBuffer ( scope ) ;
1699
+
1700
+ expect ( scope . adapter . isBOF ( ) ) . toBe ( true ) ;
1701
+ expect ( scope . adapter . isEOF ( ) ) . toBe ( true ) ;
1702
+ expect ( scope . adapter . bufferFirst ) . toBe ( 'item2' ) ;
1703
+ expect ( scope . adapter . bufferLast ) . toBe ( 'item6' ) ;
1704
+ expect ( scope . adapter . bufferLength ) . toBe ( 5 ) ;
1705
+ }
1706
+ ) ;
1707
+ } ) ;
1708
+
1686
1709
} ) ;
1687
1710
1688
1711
} ) ;
0 commit comments