Index: third_party/pkg/angular/test/routing/ng_view_spec.dart |
diff --git a/third_party/pkg/angular/test/routing/ng_view_spec.dart b/third_party/pkg/angular/test/routing/ng_view_spec.dart |
index 99edd1d4f0e26211b45921721f4d98890262d686..c8f6968db7c77c10c86f3f77e0655e0fa8fb7f32 100644 |
--- a/third_party/pkg/angular/test/routing/ng_view_spec.dart |
+++ b/third_party/pkg/angular/test/routing/ng_view_spec.dart |
@@ -10,13 +10,13 @@ main() { |
TestBed _; |
Router router; |
- beforeEach(module((Module m) { |
- m |
+ beforeEachModule((Module module) { |
+ module |
..install(new AngularMockModule()) |
..type(RouteInitializerFn, implementedBy: FlatRouteInitializer); |
- })); |
+ }); |
- beforeEach(inject((TestBed tb, Router _router, TemplateCache templates) { |
+ beforeEach((TestBed tb, Router _router, TemplateCache templates) { |
_ = tb; |
router = _router; |
@@ -24,52 +24,57 @@ main() { |
'<h1>Foo</h1>')); |
templates.put('bar.html', new HttpResponse(200, |
'<h1>Bar</h1>')); |
- })); |
+ }); |
it('should switch template', async(() { |
- Element root = _.compile('<ng-view></ng-view>'); |
+ Element root = _.compile('<div><ng-view></ng-view></div>'); |
expect(root.text).toEqual(''); |
router.route('/foo'); |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual('Foo'); |
router.route('/bar'); |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual('Bar'); |
router.route('/foo'); |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual('Foo'); |
})); |
it('should switch template when route is already active', async(() { |
// Force the routing system to initialize. |
- _.compile('<ng-view></ng-view>'); |
+ _.compile('<div><ng-view></ng-view></div>'); |
router.route('/foo'); |
microLeap(); |
- Element root = _.compile('<ng-view></ng-view>'); |
+ Element root = _.compile('<div><ng-view></ng-view></div>'); |
expect(root.text).toEqual(''); |
- _.rootScope.apply(); |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual('Foo'); |
})); |
it('should clear template when route is deactivated', async(() { |
- Element root = _.compile('<ng-view></ng-view>'); |
+ Element root = _.compile('<div><ng-view></ng-view></div>'); |
expect(root.text).toEqual(''); |
router.route('/foo'); |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual('Foo'); |
router.route('/baz'); // route without a template |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual(''); |
})); |
@@ -80,13 +85,13 @@ main() { |
TestBed _; |
Router router; |
- beforeEach(module((Module m) { |
- m |
+ beforeEachModule((Module module) { |
+ module |
..install(new AngularMockModule()) |
..type(RouteInitializerFn, implementedBy: NestedRouteInitializer); |
- })); |
+ }); |
- beforeEach(inject((TestBed tb, Router _router, TemplateCache templates) { |
+ beforeEach((TestBed tb, Router _router, TemplateCache templates) { |
_ = tb; |
router = _router; |
@@ -99,37 +104,72 @@ main() { |
'<h2>Book 1234</h2>')); |
templates.put('book_read.html', new HttpResponse(200, |
'<h2>Read Book 1234</h2>')); |
- })); |
- |
+ }); |
it('should switch nested templates', async(() { |
- Element root = _.compile('<ng-view></ng-view>'); |
+ Element root = _.compile('<div><ng-view></ng-view></div>'); |
expect(root.text).toEqual(''); |
router.route('/library/all'); |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual('LibraryBooks'); |
router.route('/library/1234'); |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual('LibraryBook 1234'); |
// nothing should change here |
router.route('/library/1234/overview'); |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual('LibraryBook 1234'); |
// nothing should change here |
router.route('/library/1234/read'); |
microLeap(); |
+ _.rootScope.apply(); |
expect(root.text).toEqual('LibraryRead Book 1234'); |
})); |
+ }); |
+ |
+ |
+ describe('Inline template ngView', () { |
+ TestBed _; |
+ Router router; |
+ beforeEachModule((Module module) { |
+ module |
+ ..install(new AngularMockModule()) |
+ ..value(RouteInitializerFn, (router, views) { |
+ views.configure({ |
+ 'foo': ngRoute( |
+ path: '/foo', |
+ viewHtml: '<h1>Hello</h1>') |
+ }); |
+ }); |
+ }); |
+ |
+ beforeEach((TestBed tb, Router _router, TemplateCache templates) { |
+ _ = tb; |
+ router = _router; |
+ }); |
+ |
+ it('should switch inline templates', async(() { |
+ Element root = _.compile('<div><ng-view></ng-view></div>'); |
+ expect(root.text).toEqual(''); |
+ |
+ router.route('/foo'); |
+ microLeap(); |
+ _.rootScope.apply(); |
+ expect(root.text).toEqual('Hello'); |
+ })); |
}); |
} |
class FlatRouteInitializer implements Function { |
- void call(Router router, ViewFactory view) { |
+ void call(Router router, RouteViewFactory view) { |
router.root |
..addRoute( |
name: 'foo', |
@@ -146,7 +186,7 @@ class FlatRouteInitializer implements Function { |
} |
class NestedRouteInitializer implements Function { |
- void call(Router router, ViewFactory view) { |
+ void call(Router router, RouteViewFactory view) { |
router.root |
..addRoute( |
name: 'library', |