Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: third_party/pkg/angular/test/routing/ng_view_spec.dart

Issue 257423008: Update all Angular libs (run update_all.sh). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 library ng_view_spec; 1 library ng_view_spec;
2 2
3 import 'dart:html'; 3 import 'dart:html';
4 import '../_specs.dart'; 4 import '../_specs.dart';
5 import 'package:angular/routing/module.dart'; 5 import 'package:angular/routing/module.dart';
6 import 'package:angular/mock/module.dart'; 6 import 'package:angular/mock/module.dart';
7 7
8 main() { 8 main() {
9 describe('Flat ngView', () { 9 describe('Flat ngView', () {
10 TestBed _; 10 TestBed _;
11 Router router; 11 Router router;
12 12
13 beforeEach(module((Module m) { 13 beforeEachModule((Module module) {
14 m 14 module
15 ..install(new AngularMockModule()) 15 ..install(new AngularMockModule())
16 ..type(RouteInitializerFn, implementedBy: FlatRouteInitializer); 16 ..type(RouteInitializerFn, implementedBy: FlatRouteInitializer);
17 })); 17 });
18 18
19 beforeEach(inject((TestBed tb, Router _router, TemplateCache templates) { 19 beforeEach((TestBed tb, Router _router, TemplateCache templates) {
20 _ = tb; 20 _ = tb;
21 router = _router; 21 router = _router;
22 22
23 templates.put('foo.html', new HttpResponse(200, 23 templates.put('foo.html', new HttpResponse(200,
24 '<h1>Foo</h1>')); 24 '<h1>Foo</h1>'));
25 templates.put('bar.html', new HttpResponse(200, 25 templates.put('bar.html', new HttpResponse(200,
26 '<h1>Bar</h1>')); 26 '<h1>Bar</h1>'));
27 })); 27 });
28 28
29 29
30 it('should switch template', async(() { 30 it('should switch template', async(() {
31 Element root = _.compile('<ng-view></ng-view>'); 31 Element root = _.compile('<div><ng-view></ng-view></div>');
32 expect(root.text).toEqual(''); 32 expect(root.text).toEqual('');
33 33
34 router.route('/foo'); 34 router.route('/foo');
35 microLeap(); 35 microLeap();
36 _.rootScope.apply();
36 expect(root.text).toEqual('Foo'); 37 expect(root.text).toEqual('Foo');
37 38
38 router.route('/bar'); 39 router.route('/bar');
39 microLeap(); 40 microLeap();
41 _.rootScope.apply();
40 expect(root.text).toEqual('Bar'); 42 expect(root.text).toEqual('Bar');
41 43
42 router.route('/foo'); 44 router.route('/foo');
43 microLeap(); 45 microLeap();
46 _.rootScope.apply();
44 expect(root.text).toEqual('Foo'); 47 expect(root.text).toEqual('Foo');
45 })); 48 }));
46 49
47 50
48 it('should switch template when route is already active', async(() { 51 it('should switch template when route is already active', async(() {
49 // Force the routing system to initialize. 52 // Force the routing system to initialize.
50 _.compile('<ng-view></ng-view>'); 53 _.compile('<div><ng-view></ng-view></div>');
51 54
52 router.route('/foo'); 55 router.route('/foo');
53 microLeap(); 56 microLeap();
54 Element root = _.compile('<ng-view></ng-view>'); 57 Element root = _.compile('<div><ng-view></ng-view></div>');
55 expect(root.text).toEqual(''); 58 expect(root.text).toEqual('');
56 59
60 microLeap();
57 _.rootScope.apply(); 61 _.rootScope.apply();
58 microLeap();
59 expect(root.text).toEqual('Foo'); 62 expect(root.text).toEqual('Foo');
60 })); 63 }));
61 64
62 65
63 it('should clear template when route is deactivated', async(() { 66 it('should clear template when route is deactivated', async(() {
64 Element root = _.compile('<ng-view></ng-view>'); 67 Element root = _.compile('<div><ng-view></ng-view></div>');
65 expect(root.text).toEqual(''); 68 expect(root.text).toEqual('');
66 69
67 router.route('/foo'); 70 router.route('/foo');
68 microLeap(); 71 microLeap();
72 _.rootScope.apply();
69 expect(root.text).toEqual('Foo'); 73 expect(root.text).toEqual('Foo');
70 74
71 router.route('/baz'); // route without a template 75 router.route('/baz'); // route without a template
72 microLeap(); 76 microLeap();
77 _.rootScope.apply();
73 expect(root.text).toEqual(''); 78 expect(root.text).toEqual('');
74 })); 79 }));
75 80
76 }); 81 });
77 82
78 83
79 describe('Nested ngView', () { 84 describe('Nested ngView', () {
80 TestBed _; 85 TestBed _;
81 Router router; 86 Router router;
82 87
83 beforeEach(module((Module m) { 88 beforeEachModule((Module module) {
84 m 89 module
85 ..install(new AngularMockModule()) 90 ..install(new AngularMockModule())
86 ..type(RouteInitializerFn, implementedBy: NestedRouteInitializer); 91 ..type(RouteInitializerFn, implementedBy: NestedRouteInitializer);
87 })); 92 });
88 93
89 beforeEach(inject((TestBed tb, Router _router, TemplateCache templates) { 94 beforeEach((TestBed tb, Router _router, TemplateCache templates) {
90 _ = tb; 95 _ = tb;
91 router = _router; 96 router = _router;
92 97
93 templates.put('library.html', new HttpResponse(200, 98 templates.put('library.html', new HttpResponse(200,
94 '<div><h1>Library</h1>' 99 '<div><h1>Library</h1>'
95 '<ng-view></ng-view></div>')); 100 '<ng-view></ng-view></div>'));
96 templates.put('book_list.html', new HttpResponse(200, 101 templates.put('book_list.html', new HttpResponse(200,
97 '<h1>Books</h1>')); 102 '<h1>Books</h1>'));
98 templates.put('book_overview.html', new HttpResponse(200, 103 templates.put('book_overview.html', new HttpResponse(200,
99 '<h2>Book 1234</h2>')); 104 '<h2>Book 1234</h2>'));
100 templates.put('book_read.html', new HttpResponse(200, 105 templates.put('book_read.html', new HttpResponse(200,
101 '<h2>Read Book 1234</h2>')); 106 '<h2>Read Book 1234</h2>'));
102 })); 107 });
103
104 108
105 it('should switch nested templates', async(() { 109 it('should switch nested templates', async(() {
106 Element root = _.compile('<ng-view></ng-view>'); 110 Element root = _.compile('<div><ng-view></ng-view></div>');
107 expect(root.text).toEqual(''); 111 expect(root.text).toEqual('');
108 112
109 router.route('/library/all'); 113 router.route('/library/all');
110 microLeap(); 114 microLeap();
115 _.rootScope.apply();
111 expect(root.text).toEqual('LibraryBooks'); 116 expect(root.text).toEqual('LibraryBooks');
112 117
113 router.route('/library/1234'); 118 router.route('/library/1234');
114 microLeap(); 119 microLeap();
120 _.rootScope.apply();
115 expect(root.text).toEqual('LibraryBook 1234'); 121 expect(root.text).toEqual('LibraryBook 1234');
116 122
117 // nothing should change here 123 // nothing should change here
118 router.route('/library/1234/overview'); 124 router.route('/library/1234/overview');
119 microLeap(); 125 microLeap();
126 _.rootScope.apply();
120 expect(root.text).toEqual('LibraryBook 1234'); 127 expect(root.text).toEqual('LibraryBook 1234');
121 128
122 // nothing should change here 129 // nothing should change here
123 router.route('/library/1234/read'); 130 router.route('/library/1234/read');
124 microLeap(); 131 microLeap();
132 _.rootScope.apply();
125 expect(root.text).toEqual('LibraryRead Book 1234'); 133 expect(root.text).toEqual('LibraryRead Book 1234');
126 })); 134 }));
135 });
127 136
137
138 describe('Inline template ngView', () {
139 TestBed _;
140 Router router;
141
142 beforeEachModule((Module module) {
143 module
144 ..install(new AngularMockModule())
145 ..value(RouteInitializerFn, (router, views) {
146 views.configure({
147 'foo': ngRoute(
148 path: '/foo',
149 viewHtml: '<h1>Hello</h1>')
150 });
151 });
152 });
153
154 beforeEach((TestBed tb, Router _router, TemplateCache templates) {
155 _ = tb;
156 router = _router;
157 });
158
159 it('should switch inline templates', async(() {
160 Element root = _.compile('<div><ng-view></ng-view></div>');
161 expect(root.text).toEqual('');
162
163 router.route('/foo');
164 microLeap();
165 _.rootScope.apply();
166 expect(root.text).toEqual('Hello');
167 }));
128 }); 168 });
129 } 169 }
130 170
131 class FlatRouteInitializer implements Function { 171 class FlatRouteInitializer implements Function {
132 void call(Router router, ViewFactory view) { 172 void call(Router router, RouteViewFactory view) {
133 router.root 173 router.root
134 ..addRoute( 174 ..addRoute(
135 name: 'foo', 175 name: 'foo',
136 path: '/foo', 176 path: '/foo',
137 enter: view('foo.html')) 177 enter: view('foo.html'))
138 ..addRoute( 178 ..addRoute(
139 name: 'bar', 179 name: 'bar',
140 path: '/bar', 180 path: '/bar',
141 enter: view('bar.html')) 181 enter: view('bar.html'))
142 ..addRoute( 182 ..addRoute(
143 name: 'baz', 183 name: 'baz',
144 path: '/baz'); // route without a template 184 path: '/baz'); // route without a template
145 } 185 }
146 } 186 }
147 187
148 class NestedRouteInitializer implements Function { 188 class NestedRouteInitializer implements Function {
149 void call(Router router, ViewFactory view) { 189 void call(Router router, RouteViewFactory view) {
150 router.root 190 router.root
151 ..addRoute( 191 ..addRoute(
152 name: 'library', 192 name: 'library',
153 path: '/library', 193 path: '/library',
154 enter: view('library.html'), 194 enter: view('library.html'),
155 mount: (Route route) => route 195 mount: (Route route) => route
156 ..addRoute( 196 ..addRoute(
157 name: 'all', 197 name: 'all',
158 path: '/all', 198 path: '/all',
159 enter: view('book_list.html')) 199 enter: view('book_list.html'))
160 ..addRoute( 200 ..addRoute(
161 name: 'book', 201 name: 'book',
162 path: '/:bookId', 202 path: '/:bookId',
163 mount: (Route route) => route 203 mount: (Route route) => route
164 ..addRoute( 204 ..addRoute(
165 name: 'overview', 205 name: 'overview',
166 path: '/overview', 206 path: '/overview',
167 defaultRoute: true, 207 defaultRoute: true,
168 enter: view('book_overview.html')) 208 enter: view('book_overview.html'))
169 ..addRoute( 209 ..addRoute(
170 name: 'read', 210 name: 'read',
171 path: '/read', 211 path: '/read',
172 enter: view('book_read.html')))) 212 enter: view('book_read.html'))))
173 ..addRoute( 213 ..addRoute(
174 name: 'admin', 214 name: 'admin',
175 path: '/admin', 215 path: '/admin',
176 enter: view('admin.html')); 216 enter: view('admin.html'));
177 } 217 }
178 } 218 }
OLDNEW
« no previous file with comments | « third_party/pkg/angular/test/routing/ng_bind_route_spec.dart ('k') | third_party/pkg/angular/test/routing/routing_spec.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698