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

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

Powered by Google App Engine
This is Rietveld 408576698