@@ -5,7 +5,7 @@ import '../_specs.dart';
5
5
import 'package:angular/routing/module.dart' ;
6
6
import 'package:angular/mock/module.dart' ;
7
7
8
- main () {
8
+ main () => describe ( 'ngView' , () {
9
9
describe ('Flat ngView' , () {
10
10
TestBed _;
11
11
Router router;
@@ -98,42 +98,65 @@ main() {
98
98
beforeEach ((TestBed tb, Router _router, TemplateCache templates) {
99
99
_ = tb;
100
100
router = _router;
101
+ _.rootScope.context['flag' ] = true ;
101
102
102
103
templates.put ('library.html' , new HttpResponse (200 ,
103
104
'<div><h1>Library</h1>'
104
- '<ng-view></ng-view></div>' ));
105
+ '<ng-view ng-if="flag" ></ng-view></div>' ));
105
106
templates.put ('book_list.html' , new HttpResponse (200 ,
106
107
'<h1>Books</h1>' ));
107
108
templates.put ('book_overview.html' , new HttpResponse (200 ,
108
109
'<h2>Book 1234</h2>' ));
109
110
templates.put ('book_read.html' , new HttpResponse (200 ,
110
111
'<h2>Read Book 1234</h2>' ));
112
+ templates.put ('alt.html' , new HttpResponse (200 , 'alt' ));
111
113
});
112
114
113
115
it ('should switch nested templates' , async (() {
114
116
Element root = _.compile ('<ng-view></ng-view>' );
117
+ microLeap (); _.rootScope.apply (); microLeap ();
115
118
expect (root.text).toEqual ('' );
116
119
117
120
router.route ('/library/all' );
118
- microLeap ();
121
+ microLeap (); _.rootScope. apply (); microLeap ();
119
122
expect (root.text).toEqual ('LibraryBooks' );
120
123
121
124
router.route ('/library/1234' );
122
- microLeap ();
125
+ microLeap (); _.rootScope. apply (); microLeap ();
123
126
expect (root.text).toEqual ('LibraryBook 1234' );
124
127
125
128
// nothing should change here
126
129
router.route ('/library/1234/overview' );
127
- microLeap ();
130
+ microLeap (); _.rootScope. apply (); microLeap ();
128
131
expect (root.text).toEqual ('LibraryBook 1234' );
129
132
130
133
// nothing should change here
131
134
router.route ('/library/1234/read' );
132
- microLeap ();
135
+ microLeap (); _.rootScope. apply (); microLeap ();
133
136
expect (root.text).toEqual ('LibraryRead Book 1234' );
134
137
}));
135
- });
136
138
139
+ it ('should not attempt to destroy and already destroyed childscope' , async (() {
140
+ // This can happen with nested ng-views. Refer
141
+ // https://github.com/angular/angular.dart/issues/1182
142
+ // and repro case
143
+ // https://github.com/chirayuk/sample/tree/issue_1182_leaving_a_nested_ng_view
144
+ Element root = _.compile ('<ng-view></ng-view>' );
145
+ microLeap (); _.rootScope.apply (); microLeap ();
146
+
147
+ router.route ('/library/1234' );
148
+ microLeap (); _.rootScope.apply (); microLeap ();
149
+
150
+ expect (root.text).toEqual ('LibraryBook 1234' );
151
+
152
+ _.rootScope.context['flag' ] = false ;
153
+ microLeap (); _.rootScope.apply (); microLeap ();
154
+ router.route ('/alt' );
155
+ microLeap (); _.rootScope.apply (); microLeap ();
156
+
157
+ expect (root.text).toEqual ('alt' );
158
+ }));
159
+ });
137
160
138
161
describe ('Inline template ngView' , () {
139
162
TestBed _;
@@ -165,7 +188,7 @@ main() {
165
188
expect (root.text).toEqual ('Hello' );
166
189
}));
167
190
});
168
- }
191
+ });
169
192
170
193
class FlatRouteInitializer implements Function {
171
194
void call (Router router, RouteViewFactory views) {
@@ -193,7 +216,10 @@ class NestedRouteInitializer implements Function {
193
216
'read' : ngRoute (path: '/read' , view: 'book_read.html' ),
194
217
'admin' : ngRoute (path: '/admin' , view: 'admin.html' ),
195
218
})
196
- })
219
+ }),
220
+ 'alt' : ngRoute (
221
+ path: '/alt' ,
222
+ view: 'alt.html' ),
197
223
});
198
224
}
199
225
}
0 commit comments