11import { assert } from "./test-config" ;
2- import { Component , Input } from "@angular/core" ;
2+ import { Component , Input , ViewChild } from "@angular/core" ;
33import { ComponentFixture , async } from "@angular/core/testing" ;
44import { nsTestBedAfterEach , nsTestBedBeforeEach , nsTestBedRender } from "nativescript-angular/testing" ;
5+ import { ListViewComponent } from "nativescript-angular/directives" ;
56// import trace = require("trace");
67// trace.setCategories("ns-list-view, " + trace.categories.Navigation);
78// trace.enable();
@@ -76,11 +77,34 @@ export class TestListViewSelectorComponent {
7677 constructor ( ) { testTemplates = { first : 0 , second : 0 } ; }
7778}
7879
80+ @Component ( {
81+ selector : "list-view-default-item-template" ,
82+ template : `
83+ <GridLayout>
84+ <ListView #listView [items]="myItems"></ListView>
85+ </GridLayout>
86+ `
87+ } )
88+ export class TestDefaultItemTemplateComponent {
89+ public myItems : Array < DataItem > ;
90+ constructor ( ) {
91+ this . myItems = new Array < DataItem > ( ) ;
92+ for ( let i = 0 ; i < 100 ; i ++ ) {
93+ this . myItems . push ( new DataItem ( i , "Name " + i ) ) ;
94+ }
95+ }
96+ @ViewChild ( "listView" ) listViewElement : ListViewComponent ;
97+ onScrollListViewTo ( ) {
98+ this . listViewElement . nativeElement . scrollToIndex ( 100 ) ;
99+ }
100+ }
101+
79102describe ( "ListView-tests" , ( ) => {
80103 beforeEach ( nsTestBedBeforeEach ( [
81104 TestListViewComponent ,
82105 TestListViewSelectorComponent ,
83- ItemTemplateComponent
106+ ItemTemplateComponent ,
107+ TestDefaultItemTemplateComponent
84108 ] ) ) ;
85109 afterEach ( nsTestBedAfterEach ( false ) ) ;
86110
@@ -98,4 +122,12 @@ describe("ListView-tests", () => {
98122 assert . deepEqual ( testTemplates , { first : 2 , second : 1 } ) ;
99123 } ) ;
100124 } ) ) ;
125+
126+ it ( "'defaultTemplate' does not throw when list-view is scrolled" , async ( ( ) => {
127+ nsTestBedRender ( TestDefaultItemTemplateComponent )
128+ . then ( ( fixture : ComponentFixture < TestDefaultItemTemplateComponent > ) => {
129+ const component = fixture . componentRef . instance ;
130+ assert . doesNotThrow ( component . onScrollListViewTo . bind ( component ) ) ;
131+ } ) ;
132+ } ) ) ;
101133} ) ;
0 commit comments