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

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

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

Powered by Google App Engine
This is Rietveld 408576698