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

Side by Side Diff: third_party/pkg/angular/test/directive/ng_switch_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_switch_spec;
2
3 import '../_specs.dart';
4
5 main() => describe('ngSwitch', () {
6 TestBed _;
7
8 beforeEach(inject((TestBed tb) => _ = tb));
9
10 it('should switch on value change', inject(() {
11 var element = _.compile(
12 '<div ng-switch="select">' +
13 '<div ng-switch-when="1">first:{{name}}</div>' +
14 '<div ng-switch-when="2">second:{{name}}</div>' +
15 '<div ng-switch-when="true">true:{{name}}</div>' +
16 '</div>');
17 expect(element.innerHtml).toEqual(
18 '<!--ANCHOR: [ng-switch-when]=1--><!--ANCHOR: [ng-switch-when]=2--><!--A NCHOR: [ng-switch-when]=true-->');
19 _.rootScope.select = 1;
20 _.rootScope.$apply();
21 expect(element.text).toEqual('first:');
22 _.rootScope.name="shyam";
23 _.rootScope.$apply();
24 expect(element.text).toEqual('first:shyam');
25 _.rootScope.select = 2;
26 _.rootScope.$apply();
27 expect(element.text).toEqual('second:shyam');
28 _.rootScope.name = 'misko';
29 _.rootScope.$apply();
30 expect(element.text).toEqual('second:misko');
31 _.rootScope.select = true;
32 _.rootScope.$apply();
33 expect(element.text).toEqual('true:misko');
34 }));
35
36
37 it('should show all switch-whens that match the current value', inject(() {
38 var element = _.compile(
39 '<ul ng-switch="select">' +
40 '<li ng-switch-when="1">first:{{name}}</li>' +
41 '<li ng-switch-when="1">, first too:{{name}}</li>' +
42 '<li ng-switch-when="2">second:{{name}}</li>' +
43 '<li ng-switch-when="true">true:{{name}}</li>' +
44 '</ul>');
45 expect(element.innerHtml).toEqual('<!--ANCHOR: [ng-switch-when]=1-->'
46 '<!--ANCHOR: [ng-switch-when]=1-->'
47 '<!--ANCHOR: [ng-switch-when]=2-->'
48 '<!--ANCHOR: [ng-switch-when]=true-->');
49 _.rootScope.select = 1;
50 _.rootScope.$apply();
51 expect(element.text).toEqual('first:, first too:');
52 _.rootScope.name="shyam";
53 _.rootScope.$apply();
54 expect(element.text).toEqual('first:shyam, first too:shyam');
55 _.rootScope.select = 2;
56 _.rootScope.$apply();
57 expect(element.text).toEqual('second:shyam');
58 _.rootScope.name = 'misko';
59 _.rootScope.$apply();
60 expect(element.text).toEqual('second:misko');
61 _.rootScope.select = true;
62 _.rootScope.$apply();
63 expect(element.text).toEqual('true:misko');
64 }));
65
66
67 it('should switch on switch-when-default', inject(() {
68 var element = _.compile(
69 '<div ng-switch="select">' +
70 '<div ng-switch-when="1">one</div>' +
71 '<div ng-switch-default>other</div>' +
72 '</div ng-switch>');
73 _.rootScope.$apply();
74 expect(element.text).toEqual('other');
75 _.rootScope.select = 1;
76 _.rootScope.$apply();
77 expect(element.text).toEqual('one');
78 }));
79
80
81 it('should show all switch-when-default', inject(() {
82 var element = _.compile(
83 '<ul ng-switch="select">' +
84 '<li ng-switch-when="1">one</li>' +
85 '<li ng-switch-default>other</li>' +
86 '<li ng-switch-default>, other too</li>' +
87 '</ul>');
88 _.rootScope.$apply();
89 expect(element.text).toEqual('other, other too');
90 _.rootScope.select = 1;
91 _.rootScope.$apply();
92 expect(element.text).toEqual('one');
93 }));
94
95
96 it('should always display the elements that do not match a switch',
97 inject(() {
98 var element = _.compile(
99 '<ul ng-switch="select">' +
100 '<li>always </li>' +
101 '<li ng-switch-when="1">one </li>' +
102 '<li ng-switch-when="2">two </li>' +
103 '<li ng-switch-default>other, </li>' +
104 '<li ng-switch-default>other too </li>' +
105 '</ul>');
106 _.rootScope.$apply();
107 expect(element.text).toEqual('always other, other too ');
108 _.rootScope.select = 1;
109 _.rootScope.$apply();
110 expect(element.text).toEqual('always one ');
111 }));
112
113
114 it('should display the elements that do not have ngSwitchWhen nor ' +
115 'ngSwitchDefault at the position specified in the template, when the ' +
116 'first and last elements in the ngSwitch body do not have a ngSwitch* ' +
117 'directive', inject(() {
118 var element = _.compile(
119 '<ul ng-switch="select">' +
120 '<li>1</li>' +
121 '<li ng-switch-when="1">2</li>' +
122 '<li>3</li>' +
123 '<li ng-switch-when="2">4</li>' +
124 '<li ng-switch-default>5</li>' +
125 '<li>6</li>' +
126 '<li ng-switch-default>7</li>' +
127 '<li>8</li>' +
128 '</ul>');
129 _.rootScope.$apply();
130 expect(element.text).toEqual('135678');
131 _.rootScope.select = 1;
132 _.rootScope.$apply();
133 expect(element.text).toEqual('12368');
134 }));
135
136
137 it('should display the elements that do not have ngSwitchWhen nor ' +
138 'ngSwitchDefault at the position specified in the template when the ' +
139 'first and last elements in the ngSwitch have a ngSwitch* directive',
140 inject(() {
141 var element = _.compile(
142 '<ul ng-switch="select">' +
143 '<li ng-switch-when="1">2</li>' +
144 '<li>3</li>' +
145 '<li ng-switch-when="2">4</li>' +
146 '<li ng-switch-default>5</li>' +
147 '<li>6</li>' +
148 '<li ng-switch-default>7</li>' +
149 '</ul>');
150 _.rootScope.$apply();
151 expect(element.text).toEqual('3567');
152 _.rootScope.select = 1;
153 _.rootScope.$apply();
154 expect(element.text).toEqual('236');
155 }));
156
157
158 it('should call change on switch', inject(() {
159 var element = _.compile(
160 '<div ng-switch="url" change="name=\'works\'">' +
161 '<div ng-switch-when="a">{{name}}</div>' +
162 '</div ng-switch>');
163 _.rootScope.url = 'a';
164 _.rootScope.$apply();
165 expect(_.rootScope.name).toEqual('works');
166 expect(element.text).toEqual('works');
167 }));
168
169
170 it('should properly create and destroy child scopes', inject(() {
171 var element = _.compile(
172 '<div ng-switch="url">' +
173 '<div ng-switch-when="a" probe="probe">{{name}}</div>' +
174 '</div ng-switch>');
175 _.rootScope.$apply();
176
177 var getChildScope = () => _.rootScope.probe == null ?
178 null : _.rootScope.probe.scope;
179
180 expect(getChildScope()).toBeNull();
181
182 _.rootScope.url = 'a';
183 _.rootScope.name = 'works';
184 _.rootScope.$apply();
185 var child1 = getChildScope();
186 expect(child1).toBeNotNull();
187 expect(element.text).toEqual('works');
188 var destroyListener = jasmine.createSpy('watch listener');
189 var listenerRemove = child1.$on('\$destroy', destroyListener);
190
191 _.rootScope.url = 'x';
192 _.rootScope.$apply();
193 print(element);
194 print(getChildScope());
195 expect(getChildScope()).toBeNull();
196 expect(destroyListener).toHaveBeenCalledOnce();
197 listenerRemove();
198
199 _.rootScope.url = 'a';
200 _.rootScope.$apply();
201 var child2 = getChildScope();
202 expect(child2).toBeDefined();
203 expect(child2).not.toBe(child1);
204 }));
205 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698