1
1
import { assert } from "./test-config" ;
2
- import { Component , Input , AfterViewInit } from ' @angular/core' ;
2
+ import { Component , Input , AfterViewInit } from " @angular/core" ;
3
3
import { TestApp } from "./test-app" ;
4
+ import { RootLocator , ComponentView , getItemViewRoot } from "nativescript-angular/directives/list-view-comp" ;
5
+ import { ProxyViewContainer } from "tns-core-modules/ui/proxy-view-container" ;
4
6
5
7
// import trace = require("trace");
6
8
// trace.setCategories("ns-list-view, " + trace.categories.Navigation);
@@ -20,7 +22,7 @@ const ITEMS = [
20
22
let testTemplates : { first : number , second : number } ;
21
23
22
24
@Component ( {
23
- selector : ' list-view-setupItemView' ,
25
+ selector : " list-view-setupItemView" ,
24
26
template : `
25
27
<GridLayout>
26
28
<ListView [items]="myItems" (setupItemView)="onSetupItemView($event)">
@@ -61,7 +63,6 @@ export class ItemTemplateComponent {
61
63
<template nsTemplateKey="first">
62
64
<item-component templateName="first"></item-component>
63
65
</template>
64
-
65
66
<template nsTemplateKey="second" let-item="item">
66
67
<item-component templateName="second"></item-component>
67
68
</template>
@@ -77,7 +78,7 @@ export class TestListViewSelectorComponent {
77
78
constructor ( ) { testTemplates = { first : 0 , second : 0 } ; }
78
79
}
79
80
80
- describe ( ' ListView-tests' , ( ) => {
81
+ describe ( " ListView-tests" , ( ) => {
81
82
let testApp : TestApp = null ;
82
83
83
84
before ( ( ) => {
@@ -94,7 +95,7 @@ describe('ListView-tests', () => {
94
95
testApp . disposeComponents ( ) ;
95
96
} ) ;
96
97
97
- it ( ' setupItemView is called for every item' , ( done ) => {
98
+ it ( " setupItemView is called for every item" , ( done ) => {
98
99
return testApp . loadComponent ( TestListViewComponent ) . then ( ( componentRef ) => {
99
100
const component = componentRef . instance ;
100
101
setTimeout ( ( ) => {
@@ -106,7 +107,7 @@ describe('ListView-tests', () => {
106
107
} ) ;
107
108
108
109
109
- it ( ' itemTemplateSelector selects templates' , ( done ) => {
110
+ it ( " itemTemplateSelector selects templates" , ( done ) => {
110
111
return testApp . loadComponent ( TestListViewSelectorComponent ) . then ( ( componentRef ) => {
111
112
setTimeout ( ( ) => {
112
113
assert . deepEqual ( testTemplates , { first : 2 , second : 1 } ) ;
@@ -116,3 +117,19 @@ describe('ListView-tests', () => {
116
117
. catch ( done ) ;
117
118
} ) ;
118
119
} ) ;
120
+
121
+ describe ( "ListView item templates" , ( ) => {
122
+ it ( "destroy child ng views on unload" , ( ) => {
123
+ const childRoot = new ProxyViewContainer ( ) ;
124
+ let viewDestroyed = false ;
125
+ const view : ComponentView = {
126
+ rootNodes : [ ] ,
127
+ destroy : ( ) => {
128
+ viewDestroyed = true ;
129
+ }
130
+ } ;
131
+ const itemRoot = getItemViewRoot ( view , ( _rootNodes , _level ) => childRoot ) ;
132
+ itemRoot . notify ( { eventName : "unloaded" , object : itemRoot } ) ;
133
+ assert . isTrue ( viewDestroyed , "ng view not destroyed" ) ;
134
+ } ) ;
135
+ } ) ;
0 commit comments