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

Side by Side Diff: third_party/pkg/angular/test/directive/ng_switch_spec.dart

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

Powered by Google App Engine
This is Rietveld 408576698