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

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

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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
(Empty)
1 library ng_view_spec;
2
3 import 'dart:html';
4 import '../_specs.dart';
5 import 'package:angular/routing/module.dart';
6 import 'package:angular/mock/module.dart';
7
8 main() {
9 describe('Flat ngView', () {
10 TestBed _;
11 Router router;
12
13 beforeEach(module((Module m) {
14 m
15 ..install(new AngularMockModule())
16 ..type(RouteInitializer, implementedBy: FlatRouteInitializer);
17 }));
18
19 beforeEach(inject((TestBed tb, Router _router, TemplateCache templates) {
20 _ = tb;
21 router = _router;
22
23 templates.put('foo.html', new HttpResponse(200,
24 '<h1>Foo</h1>'));
25 templates.put('bar.html', new HttpResponse(200,
26 '<h1>Bar</h1>'));
27 }));
28
29
30 it('should switch template', async(() {
31 Element root = _.compile('<ng-view></ng-view>');
32 expect(root.text).toEqual('');
33
34 router.route('/foo');
35 microLeap();
36 expect(root.text).toEqual('Foo');
37
38 router.route('/bar');
39 microLeap();
40 expect(root.text).toEqual('Bar');
41
42 router.route('/foo');
43 microLeap();
44 expect(root.text).toEqual('Foo');
45 }));
46
47
48 it('should switch template when route is already active', async(() {
49 // Force the routing system to initialize.
50 _.compile('<ng-view></ng-view>');
51
52 router.route('/foo');
53 microLeap();
54 Element root = _.compile('<ng-view></ng-view>');
55 expect(root.text).toEqual('');
56
57 _.rootScope.$digest();
58 microLeap();
59 expect(root.text).toEqual('Foo');
60 }));
61
62
63 it('should clear template when route is deactivated', async(() {
64 Element root = _.compile('<ng-view></ng-view>');
65 expect(root.text).toEqual('');
66
67 router.route('/foo');
68 microLeap();
69 expect(root.text).toEqual('Foo');
70
71 router.route('/baz'); // route without a template
72 microLeap();
73 expect(root.text).toEqual('');
74 }));
75
76 });
77
78
79 describe('Nested ngView', () {
80 TestBed _;
81 Router router;
82
83 beforeEach(module((Module m) {
84 m
85 ..install(new AngularMockModule())
86 ..type(RouteInitializer, implementedBy: NestedRouteInitializer);
87 }));
88
89 beforeEach(inject((TestBed tb, Router _router, TemplateCache templates) {
90 _ = tb;
91 router = _router;
92
93 templates.put('library.html', new HttpResponse(200,
94 '<div><h1>Library</h1>'
95 '<ng-view></ng-view></div>'));
96 templates.put('book_list.html', new HttpResponse(200,
97 '<h1>Books</h1>'));
98 templates.put('book_overview.html', new HttpResponse(200,
99 '<h2>Book 1234</h2>'));
100 templates.put('book_read.html', new HttpResponse(200,
101 '<h2>Read Book 1234</h2>'));
102 }));
103
104
105 it('should switch nested templates', async(() {
106 Element root = _.compile('<ng-view></ng-view>');
107 expect(root.text).toEqual('');
108
109 router.route('/library/all');
110 microLeap();
111 expect(root.text).toEqual('LibraryBooks');
112
113 router.route('/library/1234');
114 microLeap();
115 expect(root.text).toEqual('LibraryBook 1234');
116
117 // nothing should change here
118 router.route('/library/1234/overview');
119 microLeap();
120 expect(root.text).toEqual('LibraryBook 1234');
121
122 // nothing should change here
123 router.route('/library/1234/read');
124 microLeap();
125 expect(root.text).toEqual('LibraryRead Book 1234');
126 }));
127
128 });
129 }
130
131 class FlatRouteInitializer implements RouteInitializer {
132 void init(Router router, ViewFactory view) {
133 router.root
134 ..addRoute(
135 name: 'foo',
136 path: '/foo',
137 enter: view('foo.html'))
138 ..addRoute(
139 name: 'bar',
140 path: '/bar',
141 enter: view('bar.html'))
142 ..addRoute(
143 name: 'baz',
144 path: '/baz'); // route without a template
145 }
146 }
147
148 class NestedRouteInitializer implements RouteInitializer {
149 void init(Router router, ViewFactory view) {
150 router.root
151 ..addRoute(
152 name: 'library',
153 path: '/library',
154 enter: view('library.html'),
155 mount: (Route route) => route
156 ..addRoute(
157 name: 'all',
158 path: '/all',
159 enter: view('book_list.html'))
160 ..addRoute(
161 name: 'book',
162 path: '/:bookId',
163 mount: (Route route) => route
164 ..addRoute(
165 name: 'overview',
166 path: '/overview',
167 defaultRoute: true,
168 enter: view('book_overview.html'))
169 ..addRoute(
170 name: 'read',
171 path: '/read',
172 enter: view('book_read.html'))))
173 ..addRoute(
174 name: 'admin',
175 path: '/admin',
176 enter: view('admin.html'));
177 }
178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698