11describe ( 'uiScroll' , function ( ) {
22 'use strict' ;
33
4+ let datasource ;
45 beforeEach ( module ( 'ui.scroll' ) ) ;
56 beforeEach ( module ( 'ui.scroll.test.datasources' ) ) ;
67
8+ const injectDatasource = ( datasourceToken ) =>
9+ beforeEach (
10+ inject ( [ datasourceToken , function ( _datasource ) {
11+ datasource = _datasource ;
12+ } ] )
13+ ) ;
14+
715 describe ( 'applyUpdates tests\n' , function ( ) {
16+ injectDatasource ( 'myOnePageDatasource' ) ;
817 var scrollSettings = { datasource : 'myOnePageDatasource' , adapter : 'adapter' } ;
918
1019 it ( 'should create adapter object' , function ( ) {
@@ -193,6 +202,8 @@ describe('uiScroll', function () {
193202 runTest ( scrollSettings ,
194203 function ( viewport , scope ) {
195204
205+ datasource ;
206+
196207 scope . adapter . applyUpdates (
197208 function ( item ) {
198209 if ( item === 'one' ) {
@@ -1216,7 +1227,7 @@ describe('uiScroll', function () {
12161227 describe ( 'prepend tests\n' , function ( ) {
12171228
12181229 it ( 'should prepend two rows to the dataset' , function ( ) {
1219- runTest ( { datasource : 'myOnePageDatasource' , adapter : 'adapter' } ,
1230+ runTest ( { datasource : 'myOnePageDatasource' , adapter : 'adapter' } ,
12201231 function ( viewport , scope ) {
12211232
12221233 scope . adapter . prepend ( [ 'prepended one' , 'prepended two' ] ) ;
@@ -1250,8 +1261,28 @@ describe('uiScroll', function () {
12501261 ) ;
12511262 } ) ;
12521263
1264+ it ( 'should prepend two rows to the dataset with immutableTop option' , function ( ) {
1265+ runTest ( { datasource : 'myOnePageDatasource' , adapter : 'adapter' } ,
1266+ function ( viewport , scope ) {
1267+
1268+ scope . adapter . prepend ( [ 'prepended one' , 'prepended two' ] , { immutableTop : true } ) ;
1269+
1270+ expect ( viewport . children ( ) . length ) . toBe ( 7 ) ;
1271+ expect ( viewport . children ( ) [ 1 ] . innerHTML ) . toBe ( '1: prepended one' ) ;
1272+ expect ( viewport . children ( ) [ 2 ] . innerHTML ) . toBe ( '2: prepended two' ) ;
1273+ expect ( viewport . children ( ) [ 3 ] . innerHTML ) . toBe ( '3: one' ) ;
1274+ expect ( viewport . children ( ) [ 4 ] . innerHTML ) . toBe ( '4: two' ) ;
1275+ expect ( viewport . children ( ) [ 5 ] . innerHTML ) . toBe ( '5: three' ) ;
1276+
1277+ expect ( scope . adapter ) . toBeTruthy ( ) ;
1278+ expect ( scope . adapter . topVisibleElement [ 0 ] . innerHTML ) . toBe ( '1: prepended one' ) ;
1279+ expect ( scope . adapter . bottomVisibleElement [ 0 ] . innerHTML ) . toBe ( '5: three' ) ;
1280+ }
1281+ ) ;
1282+ } ) ;
1283+
12531284 it ( 'should prepend two rows to the empty dataset' , function ( ) {
1254- runTest ( { datasource : 'myEmptyDatasource' , adapter : 'adapter' } ,
1285+ runTest ( { datasource : 'myEmptyDatasource' , adapter : 'adapter' } ,
12551286 function ( viewport , scope ) {
12561287
12571288 scope . adapter . prepend ( [ 'prepended one' , 'prepended two' ] ) ;
@@ -1273,6 +1304,23 @@ describe('uiScroll', function () {
12731304 ) ;
12741305 } ) ;
12751306
1307+ it ( 'should prepend two rows to the empty dataset with immutableTop option' , function ( ) {
1308+ runTest ( { datasource : 'myEmptyDatasource' , adapter : 'adapter' } ,
1309+ function ( viewport , scope ) {
1310+
1311+ scope . adapter . prepend ( [ 'prepended one' , 'prepended two' ] , { immutableTop : true } ) ;
1312+
1313+ expect ( viewport . children ( ) . length ) . toBe ( 4 ) ;
1314+ expect ( viewport . children ( ) [ 1 ] . innerHTML ) . toBe ( '1: prepended one' ) ;
1315+ expect ( viewport . children ( ) [ 2 ] . innerHTML ) . toBe ( '2: prepended two' ) ;
1316+
1317+ expect ( scope . adapter ) . toBeTruthy ( ) ;
1318+ expect ( scope . adapter . topVisibleElement [ 0 ] . innerHTML ) . toBe ( '1: prepended one' ) ;
1319+ expect ( scope . adapter . bottomVisibleElement [ 0 ] . innerHTML ) . toBe ( '2: prepended two' ) ;
1320+ }
1321+ ) ;
1322+ } ) ;
1323+
12761324 } ) ;
12771325
12781326 describe ( 'adapter reload tests' , function ( ) {
0 commit comments