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

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

Issue 176943008: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 input_select_spec; 1 library input_select_spec;
2 2
3 import '../_specs.dart'; 3 import '../_specs.dart';
4 4
5 //TODO(misko): re-enabled disabled tests once we have forms. 5 //TODO(misko): re-enabled disabled tests once we have forms.
6 6
7 main() { 7 main() {
8 describe('input-select', () { 8 describe('input-select', () {
9 9
10 describe('ng-value', () { 10 describe('ng-value', () {
11 TestBed _; 11 TestBed _;
12 beforeEach(inject((TestBed tb) => _ = tb)); 12 beforeEach(inject((TestBed tb) => _ = tb));
13 13
14 it('should retrieve using ng-value', () { 14 it('should retrieve using ng-value', () {
15 _.compile( 15 _.compile(
16 '<select ng-model="robot" probe="p">' 16 '<select ng-model="robot" probe="p">'
17 '<option ng-repeat="r in robots" ng-value="r">{{r.name}}</option>' 17 '<option ng-repeat="r in robots" ng-value="r">{{r.name}}</option>'
18 '</select>'); 18 '</select>');
19 var r2d2 = { "name":"r2d2"}; 19 var r2d2 = {"name":"r2d2"};
20 var c3p0 = {"name":"c3p0"}; 20 var c3p0 = {"name":"c3p0"};
21 _.rootScope.robots = [ r2d2, c3p0 ]; 21 _.rootScope.context['robots'] = [ r2d2, c3p0 ];
22 _.rootScope.$digest(); 22 _.rootScope.apply();
23 _.selectOption(_.rootElement, 'c3p0'); 23 _.selectOption(_.rootElement, 'c3p0');
24 expect(_.rootScope.robot).toEqual(c3p0); 24 expect(_.rootScope.context['robot']).toEqual(c3p0);
25 25
26 _.rootScope.robot = r2d2; 26 _.rootScope.context['robot'] = r2d2;
27 _.rootScope.$digest(); 27 _.rootScope.apply();
28 expect(_.rootScope.robot).toEqual(r2d2); 28 expect(_.rootScope.context['robot']).toEqual(r2d2);
29 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']); 29 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']);
30 }); 30 });
31 31
32 it('should retrieve using ng-value', () { 32 it('should retrieve using ng-value', () {
33 _.compile( 33 _.compile(
34 '<select ng-model="robot" probe="p" multiple>' 34 '<select ng-model="robot" probe="p" multiple>'
35 '<option ng-repeat="r in robots" ng-value="r">{{r.name}}</option>' 35 '<option ng-repeat="r in robots" ng-value="r">{{r.name}}</option>'
36 '</select>'); 36 '</select>');
37 var r2d2 = { "name":"r2d2"}; 37 var r2d2 = { "name":"r2d2"};
38 var c3p0 = {"name":"c3p0"}; 38 var c3p0 = {"name":"c3p0"};
39 _.rootScope.robots = [ r2d2, c3p0 ]; 39 _.rootScope.context['robots'] = [ r2d2, c3p0 ];
40 _.rootScope.$digest(); 40 _.rootScope.apply();
41 _.selectOption(_.rootElement, 'c3p0'); 41 _.selectOption(_.rootElement, 'c3p0');
42 expect(_.rootScope.robot).toEqual([c3p0]); 42 expect(_.rootScope.context['robot']).toEqual([c3p0]);
43 43
44 _.rootScope.robot = [r2d2]; 44 _.rootScope.context['robot'] = [r2d2];
45 _.rootScope.$digest(); 45 _.rootScope.apply();
46 expect(_.rootScope.robot).toEqual([r2d2]); 46 expect(_.rootScope.context['robot']).toEqual([r2d2]);
47 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']); 47 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']);
48 }); 48 });
49 }); 49 });
50 50
51 TestBed _; 51 TestBed _;
52 52
53 beforeEach(inject((TestBed tb) => _ = tb)); 53 beforeEach(inject((TestBed tb) => _ = tb));
54 54
55 describe('select-one', () { 55 describe('select-one', () {
56 it('should compile children of a select without a ngModel, but not create a model for it', 56 it('should compile children of a select without a ngModel, but not create a model for it',
57 () { 57 () {
58 _.compile( 58 _.compile(
59 '<select>' 59 '<select>'
60 '<option selected="true">{{a}}</option>' 60 '<option selected="true">{{a}}</option>'
61 '<option value="">{{b}}</option>' 61 '<option value="">{{b}}</option>'
62 '<option>C</option>' 62 '<option>C</option>'
63 '</select>'); 63 '</select>');
64 _.rootScope.$apply(() { 64 _.rootScope.apply(() {
65 _.rootScope['a'] = 'foo'; 65 _.rootScope.context['a'] = 'foo';
66 _.rootScope['b'] = 'bar'; 66 _.rootScope.context['b'] = 'bar';
67 }); 67 });
68 68
69 expect(_.rootElement.text).toEqual('foobarC'); 69 expect(_.rootElement.text).toEqual('foobarC');
70 }); 70 });
71 71
72 it('should not interfere with selection via selected attr if ngModel direc tive is not present', 72 it('should not interfere with selection via selected attr if ngModel direc tive is not present',
73 () { 73 () {
74 _.compile( 74 _.compile(
75 '<select>' 75 '<select>'
76 '<option>not me</option>' 76 '<option>not me</option>'
77 '<option selected>me!</option>' 77 '<option selected>me!</option>'
78 '<option>nah</option>' 78 '<option>nah</option>'
79 '</select>'); 79 '</select>');
80 _.rootScope.$digest(); 80 _.rootScope.apply();
81 81
82 expect(_.rootElement).toEqualSelect(['not me', ['me!'], 'nah']); 82 expect(_.rootElement).toEqualSelect(['not me', ['me!'], 'nah']);
83 }); 83 });
84 84
85 it('should work with repeated value options', () { 85 it('should work with repeated value options', () {
86 _.compile( 86 _.compile(
87 '<select ng-model="robot" probe="p">' 87 '<select ng-model="robot" probe="p">'
88 '<option ng-repeat="r in robots">{{r}}</option>' 88 '<option ng-repeat="r in robots">{{r}}</option>'
89 '</select>'); 89 '</select>');
90 90
91 _.rootScope['robots'] = ['c3p0', 'r2d2']; 91 _.rootScope.context['robots'] = ['c3p0', 'r2d2'];
92 _.rootScope['robot'] = 'r2d2'; 92 _.rootScope.context['robot'] = 'r2d2';
93 _.rootScope.$apply(); 93 _.rootScope.apply();
94 94
95 var select = _.rootScope['p'].directive(InputSelectDirective); 95 var select = _.rootScope.context['p'].directive(InputSelectDirective);
96 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]); 96 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]);
97 97
98 _.rootElement.querySelectorAll('option')[0].selected = true; 98 _.rootElement.querySelectorAll('option')[0].selected = true;
99 _.triggerEvent(_.rootElement, 'change'); 99 _.triggerEvent(_.rootElement, 'change');
100 100
101 101
102 expect(_.rootElement).toEqualSelect([['c3p0'], 'r2d2']); 102 expect(_.rootElement).toEqualSelect([['c3p0'], 'r2d2']);
103 expect(_.rootScope['robot']).toEqual('c3p0'); 103 expect(_.rootScope.context['robot']).toEqual('c3p0');
104 104
105 _.rootScope.$apply(() { 105 _.rootScope.apply(() {
106 _.rootScope['robots'].insert(0, 'wallee'); 106 _.rootScope.context['robots'].insert(0, 'wallee');
107 }); 107 });
108 expect(_.rootElement).toEqualSelect(['wallee', ['c3p0'], 'r2d2']); 108 expect(_.rootElement).toEqualSelect(['wallee', ['c3p0'], 'r2d2']);
109 expect(_.rootScope['robot']).toEqual('c3p0'); 109 expect(_.rootScope.context['robot']).toEqual('c3p0');
110 110
111 _.rootScope.$apply(() { 111 _.rootScope.apply(() {
112 _.rootScope['robots'] = ['c3p0+', 'r2d2+']; 112 _.rootScope.context['robots'] = ['c3p0+', 'r2d2+'];
113 _.rootScope['robot'] = 'r2d2+'; 113 _.rootScope.context['robot'] = 'r2d2+';
114 }); 114 });
115 115
116 expect(_.rootElement).toEqualSelect(['c3p0+', ['r2d2+']]); 116 expect(_.rootElement).toEqualSelect(['c3p0+', ['r2d2+']]);
117 expect(_.rootScope['robot']).toEqual('r2d2+'); 117 expect(_.rootScope.context['robot']).toEqual('r2d2+');
118 }); 118 });
119 119
120 describe('empty option', () { 120 describe('empty option', () {
121 it('should select the empty option when model is undefined', () { 121 it('should select the empty option when model is undefined', () {
122 _.compile( 122 _.compile(
123 '<select ng-model="robot">' + 123 '<select ng-model="robot">' +
124 '<option value="">--select--</option>' + 124 '<option value="">--select--</option>' +
125 '<option value="x">robot x</option>' + 125 '<option value="x">robot x</option>' +
126 '<option value="y">robot y</option>' + 126 '<option value="y">robot y</option>' +
127 '</select>'); 127 '</select>');
128 _.rootScope.$digest(); 128 _.rootScope.apply();
129 129
130 expect(_.rootElement).toEqualSelect([[''], 'x', 'y']); 130 expect(_.rootElement).toEqualSelect([[''], 'x', 'y']);
131 }); 131 });
132 132
133 it('should support defining an empty option anywhere in the option list' , () { 133 it('should support defining an empty option anywhere in the option list' , () {
134 _.compile( 134 _.compile(
135 '<select ng-model="robot">' + 135 '<select ng-model="robot">' +
136 '<option value="x">robot x</option>' + 136 '<option value="x">robot x</option>' +
137 '<option value="">--select--</option>' + 137 '<option value="">--select--</option>' +
138 '<option value="y">robot y</option>' + 138 '<option value="y">robot y</option>' +
139 '</select>'); 139 '</select>');
140 _.rootScope.$digest(); 140 _.rootScope.apply();
141 141
142 expect(_.rootElement).toEqualSelect(['x', [''], 'y']); 142 expect(_.rootElement).toEqualSelect(['x', [''], 'y']);
143 }); 143 });
144 144
145 it('should set the model to empty string when empty option is selected', () { 145 it('should set the model to empty string when empty option is selected', () {
146 _.rootScope['robot'] = 'x'; 146 _.rootScope.context['robot'] = 'x';
147 _.compile( 147 _.compile(
148 '<select ng-model="robot" probe="p">' + 148 '<select ng-model="robot" probe="p">' +
149 '<option value="">--select--</option>' + 149 '<option value="">--select--</option>' +
150 '<option value="x">robot x</option>' + 150 '<option value="x">robot x</option>' +
151 '<option value="y">robot y</option>' + 151 '<option value="y">robot y</option>' +
152 '</select>'); 152 '</select>');
153 _.rootScope.$digest(); 153 _.rootScope.apply();
154 154
155 var select = _.rootScope['p'].directive(InputSelectDirective); 155 var select = _.rootScope.context['p'].directive(InputSelectDirective);
156 156
157 expect(_.rootElement).toEqualSelect(['', ['x'], 'y']); 157 expect(_.rootElement).toEqualSelect(['', ['x'], 'y']);
158 158
159 _.selectOption(_.rootElement, '--select--'); 159 _.selectOption(_.rootElement, '--select--');
160 160
161 expect(_.rootElement).toEqualSelect([[''], 'x', 'y']); 161 expect(_.rootElement).toEqualSelect([[''], 'x', 'y']);
162 expect(_.rootScope['robot']).toEqual(null); 162 expect(_.rootScope.context['robot']).toEqual(null);
163 }); 163 });
164 164
165 describe('interactions with repeated options', () { 165 describe('interactions with repeated options', () {
166 it('should select empty option when model is undefined', () { 166 it('should select empty option when model is undefined', () {
167 _.rootScope['robots'] = ['c3p0', 'r2d2']; 167 _.rootScope.context['robots'] = ['c3p0', 'r2d2'];
168 _.compile( 168 _.compile(
169 '<select ng-model="robot">' + 169 '<select ng-model="robot">' +
170 '<option value="">--select--</option>' + 170 '<option value="">--select--</option>' +
171 '<option ng-repeat="r in robots">{{r}}</option>' + 171 '<option ng-repeat="r in robots">{{r}}</option>' +
172 '</select>'); 172 '</select>');
173 _.rootScope.$digest(); 173 _.rootScope.apply();
174 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']); 174 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']);
175 }); 175 });
176 176
177 it('should set model to empty string when selected', () { 177 it('should set model to empty string when selected', () {
178 _.rootScope['robots'] = ['c3p0', 'r2d2']; 178 _.rootScope.context['robots'] = ['c3p0', 'r2d2'];
179 _.compile( 179 _.compile(
180 '<select ng-model="robot" probe="p">' + 180 '<select ng-model="robot" probe="p">' +
181 '<option value="">--select--</option>' + 181 '<option value="">--select--</option>' +
182 '<option ng-repeat="r in robots">{{r}}</option>' + 182 '<option ng-repeat="r in robots">{{r}}</option>' +
183 '</select>'); 183 '</select>');
184 _.rootScope.$digest(); 184 _.rootScope.apply();
185 var select = _.rootScope['p'].directive(InputSelectDirective); 185 var select = _.rootScope.context['p'].directive(InputSelectDirective );
186 186
187 _.selectOption(_.rootElement, 'c3p0'); 187 _.selectOption(_.rootElement, 'c3p0');
188 expect(_.rootElement).toEqualSelect(['', ['c3p0'], 'r2d2']); 188 expect(_.rootElement).toEqualSelect(['', ['c3p0'], 'r2d2']);
189 expect( _.rootScope['robot']).toEqual('c3p0'); 189 expect( _.rootScope.context['robot']).toEqual('c3p0');
190 190
191 _.selectOption(_.rootElement, '--select--'); 191 _.selectOption(_.rootElement, '--select--');
192 192
193 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']); 193 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']);
194 expect( _.rootScope['robot']).toEqual(null); 194 expect( _.rootScope.context['robot']).toEqual(null);
195 }); 195 });
196 196
197 it('should not break if both the select and repeater models change at once', () { 197 it('should not break if both the select and repeater models change at once', () {
198 _.compile( 198 _.compile(
199 '<select ng-model="robot">' + 199 '<select ng-model="robot">' +
200 '<option value="">--select--</option>' + 200 '<option value="">--select--</option>' +
201 '<option ng-repeat="r in robots">{{r}}</option>' + 201 '<option ng-repeat="r in robots">{{r}}</option>' +
202 '</select>'); 202 '</select>');
203 _.rootScope.$apply(() { 203 _.rootScope.apply(() {
204 _.rootScope['robots'] = ['c3p0', 'r2d2']; 204 _.rootScope.context['robots'] = ['c3p0', 'r2d2'];
205 _.rootScope['robot'] = 'c3p0'; 205 _.rootScope.context['robot'] = 'c3p0';
206 }); 206 });
207 207
208 expect(_.rootElement).toEqualSelect(['', ['c3p0'], 'r2d2']); 208 expect(_.rootElement).toEqualSelect(['', ['c3p0'], 'r2d2']);
209 209
210 _.rootScope.$apply(() { 210 _.rootScope.apply(() {
211 _.rootScope['robots'] = ['wallee']; 211 _.rootScope.context['robots'] = ['wallee'];
212 _.rootScope['robot'] = ''; 212 _.rootScope.context['robot'] = '';
213 }); 213 });
214 214
215 expect(_.rootElement).toEqualSelect([[''], 'wallee']); 215 expect(_.rootElement).toEqualSelect([[''], 'wallee']);
216 }); 216 });
217 }); 217 });
218 218
219 describe('unknown option', () { 219 describe('unknown option', () {
220 220
221 it("should insert&select temporary unknown option when no options-mode l match", () { 221 it("should insert&select temporary unknown option when no options-mode l match", () {
222 _.compile( 222 _.compile(
223 '<select ng-model="robot">' + 223 '<select ng-model="robot">' +
224 '<option>c3p0</option>' + 224 '<option>c3p0</option>' +
225 '<option>r2d2</option>' + 225 '<option>r2d2</option>' +
226 '</select>'); 226 '</select>');
227 _.rootScope.$digest(); 227 _.rootScope.apply();
228 expect(_.rootElement).toEqualSelect([['?'], 'c3p0', 'r2d2']); 228 expect(_.rootElement).toEqualSelect([['?'], 'c3p0', 'r2d2']);
229 229
230 _.rootScope.$apply(() { 230 _.rootScope.apply(() {
231 _.rootScope['robot'] = 'r2d2'; 231 _.rootScope.context['robot'] = 'r2d2';
232 }); 232 });
233 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]); 233 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]);
234 234
235 235
236 _.rootScope.$apply(() { 236 _.rootScope.apply(() {
237 _.rootScope['robot'] = "wallee"; 237 _.rootScope.context['robot'] = "wallee";
238 }); 238 });
239 expect(_.rootElement).toEqualSelect([['?'], 'c3p0', 'r2d2']); 239 expect(_.rootElement).toEqualSelect([['?'], 'c3p0', 'r2d2']);
240 }); 240 });
241 241
242 it("should NOT insert temporary unknown option when model is undefined and empty " + 242 it("should NOT insert temporary unknown option when model is undefined and empty " +
243 "options is present", () { 243 "options is present", () {
244 _.compile( 244 _.compile(
245 '<select ng-model="robot">' + 245 '<select ng-model="robot">' +
246 '<option value="">--select--</option>' + 246 '<option value="">--select--</option>' +
247 '<option>c3p0</option>' + 247 '<option>c3p0</option>' +
248 '<option>r2d2</option>' + 248 '<option>r2d2</option>' +
249 '</select>'); 249 '</select>');
250 _.rootScope.$digest(); 250 _.rootScope.apply();
251 251
252 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']); 252 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']);
253 expect(_.rootScope['robot']).toEqual(null); 253 expect(_.rootScope.context['robot']).toEqual(null);
254 254
255 _.rootScope.$apply(() { 255 _.rootScope.apply(() {
256 _.rootScope['robot'] = 'wallee'; 256 _.rootScope.context['robot'] = 'wallee';
257 }); 257 });
258 expect(_.rootElement).toEqualSelect([['?'], '', 'c3p0', 'r2d2']); 258 expect(_.rootElement).toEqualSelect([['?'], '', 'c3p0', 'r2d2']);
259 259
260 _.rootScope.$apply(() { 260 _.rootScope.apply(() {
261 _.rootScope['robot'] = 'r2d2'; 261 _.rootScope.context['robot'] = 'r2d2';
262 }); 262 });
263 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]); 263 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]);
264 264
265 _.rootScope.$apply(() { 265 _.rootScope.apply(() {
266 _.rootScope['robot'] = null; 266 _.rootScope.context['robot'] = null;
267 }); 267 });
268 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']); 268 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']);
269 }); 269 });
270 270
271 it("should insert&select temporary unknown option when no options-mode l match, empty " + 271 it("should insert&select temporary unknown option when no options-mode l match, empty " +
272 "option is present and model is defined", () { 272 "option is present and model is defined", () {
273 _.rootScope['robot'] = 'wallee'; 273 _.rootScope.context['robot'] = 'wallee';
274 _.compile( 274 _.compile(
275 '<select ng-model="robot">' + 275 '<select ng-model="robot">' +
276 '<option value="">--select--</option>' + 276 '<option value="">--select--</option>' +
277 '<option>c3p0</option>' + 277 '<option>c3p0</option>' +
278 '<option>r2d2</option>' + 278 '<option>r2d2</option>' +
279 '</select>'); 279 '</select>');
280 _.rootScope.$digest(); 280 _.rootScope.apply();
281 281
282 expect(_.rootElement).toEqualSelect([['?'], '', 'c3p0', 'r2d2']); 282 expect(_.rootElement).toEqualSelect([['?'], '', 'c3p0', 'r2d2']);
283 283
284 _.rootScope.$apply(() { 284 _.rootScope.apply(() {
285 _.rootScope['robot'] = 'r2d2'; 285 _.rootScope.context['robot'] = 'r2d2';
286 }); 286 });
287 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]); 287 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]);
288 }); 288 });
289 289
290 describe('interactions with repeated options', () { 290 describe('interactions with repeated options', () {
291 it('should work with repeated options', () { 291 it('should work with repeated options', () {
292 _.rootScope['robots'] = []; 292 _.rootScope.context['robots'] = [];
293 _.compile( 293 _.compile(
294 '<select ng-model="robot">' + 294 '<select ng-model="robot">' +
295 '<option ng-repeat="r in robots">{{r}}</option>' + 295 '<option ng-repeat="r in robots">{{r}}</option>' +
296 '</select>'); 296 '</select>');
297 _.rootScope.$apply(() { 297 _.rootScope.apply(() {
298 _.rootScope['robots'] = []; 298 _.rootScope.context['robots'] = [];
299 }); 299 });
300 300
301 expect(_.rootElement).toEqualSelect([['?']]); 301 expect(_.rootElement).toEqualSelect([['?']]);
302 expect(_.rootScope['robot']).toEqual(null); 302 expect(_.rootScope.context['robot']).toEqual(null);
303 303
304 _.rootScope.$apply(() { 304 _.rootScope.apply(() {
305 _.rootScope['robot'] = 'r2d2'; 305 _.rootScope.context['robot'] = 'r2d2';
306 }); 306 });
307 expect(_.rootElement).toEqualSelect([['?']]); 307 expect(_.rootElement).toEqualSelect([['?']]);
308 expect(_.rootScope['robot']).toEqual('r2d2'); 308 expect(_.rootScope.context['robot']).toEqual('r2d2');
309 309
310 _.rootScope.$apply(() { 310 _.rootScope.apply(() {
311 _.rootScope['robots'] = ['c3p0', 'r2d2']; 311 _.rootScope.context['robots'] = ['c3p0', 'r2d2'];
312 }); 312 });
313 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]); 313 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]);
314 expect(_.rootScope['robot']).toEqual('r2d2'); 314 expect(_.rootScope.context['robot']).toEqual('r2d2');
315 }); 315 });
316 316
317 it('should work with empty option and repeated options', () { 317 it('should work with empty option and repeated options', () {
318 _.compile( 318 _.compile(
319 '<select ng-model="robot">' + 319 '<select ng-model="robot">' +
320 '<option value="">--select--</option>' + 320 '<option value="">--select--</option>' +
321 '<option ng-repeat="r in robots">{{r}}</option>' + 321 '<option ng-repeat="r in robots">{{r}}</option>' +
322 '</select>'); 322 '</select>');
323 _.rootScope.$apply(() { 323 _.rootScope.apply(() {
324 _.rootScope['robots'] = []; 324 _.rootScope.context['robots'] = [];
325 }); 325 });
326 326
327 expect(_.rootElement).toEqualSelect([['']]); 327 expect(_.rootElement).toEqualSelect([['']]);
328 expect(_.rootScope['robot']).toEqual(null); 328 expect(_.rootScope.context['robot']).toEqual(null);
329 329
330 _.rootScope.$apply(() { 330 _.rootScope.apply(() {
331 _.rootScope['robot'] = 'r2d2'; 331 _.rootScope.context['robot'] = 'r2d2';
332 }); 332 });
333 expect(_.rootElement).toEqualSelect([['?'], '']); 333 expect(_.rootElement).toEqualSelect([['?'], '']);
334 expect(_.rootScope['robot']).toEqual('r2d2'); 334 expect(_.rootScope.context['robot']).toEqual('r2d2');
335 335
336 _.rootScope.$apply(() { 336 _.rootScope.apply(() {
337 _.rootScope['robots'] = ['c3p0', 'r2d2']; 337 _.rootScope.context['robots'] = ['c3p0', 'r2d2'];
338 }); 338 });
339 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]); 339 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]);
340 expect(_.rootScope['robot']).toEqual('r2d2'); 340 expect(_.rootScope.context['robot']).toEqual('r2d2');
341 }); 341 });
342 342
343 it('should insert unknown element when repeater shrinks and selected option is ' + 343 it('should insert unknown element when repeater shrinks and selected option is ' +
344 'unavailable', () { 344 'unavailable', () {
345 345
346 _.compile( 346 _.compile(
347 '<select ng-model="robot">' + 347 '<select ng-model="robot">' +
348 '<option ng-repeat="r in robots">{{r}}</option>' + 348 '<option ng-repeat="r in robots">{{r}}</option>' +
349 '</select>'); 349 '</select>');
350 _.rootScope.$apply(() { 350 _.rootScope.apply(() {
351 _.rootScope['robots'] = ['c3p0', 'r2d2']; 351 _.rootScope.context['robots'] = ['c3p0', 'r2d2'];
352 _.rootScope['robot'] = 'r2d2'; 352 _.rootScope.context['robot'] = 'r2d2';
353 }); 353 });
354 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]); 354 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]);
355 expect(_.rootScope['robot']).toEqual('r2d2'); 355 expect(_.rootScope.context['robot']).toEqual('r2d2');
356 356
357 _.rootScope.$apply(() { 357 _.rootScope.apply(() {
358 _.rootScope['robots'].remove('r2d2'); 358 _.rootScope.context['robots'].remove('r2d2');
359 }); 359 });
360 expect(_.rootScope['robot']).toEqual('r2d2'); 360 expect(_.rootScope.context['robot']).toEqual('r2d2');
361 expect(_.rootElement).toEqualSelect([['?'], 'c3p0']); 361 expect(_.rootElement).toEqualSelect([['?'], 'c3p0']);
362 362
363 _.rootScope.$apply(() { 363 _.rootScope.apply(() {
364 _.rootScope['robots'].insert(0, 'r2d2'); 364 _.rootScope.context['robots'].insert(0, 'r2d2');
365 }); 365 });
366 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']); 366 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']);
367 expect(_.rootScope['robot']).toEqual('r2d2'); 367 expect(_.rootScope.context['robot']).toEqual('r2d2');
368 368
369 _.rootScope.$apply(() { 369 _.rootScope.apply(() {
370 _.rootScope['robots'].clear(); 370 _.rootScope.context['robots'].clear();
371 }); 371 });
372 372
373 expect(_.rootElement).toEqualSelect([['?']]); 373 expect(_.rootElement).toEqualSelect([['?']]);
374 expect(_.rootScope['robot']).toEqual('r2d2'); 374 expect(_.rootScope.context['robot']).toEqual('r2d2');
375 }); 375 });
376 }); 376 });
377 }); 377 });
378 }); 378 });
379 379
380 it('issue #392', () { 380 it('issue #392', () {
381 _.compile( 381 _.compile(
382 '<div>' + 382 '<div>' +
383 '<div ng-if="attached">' + 383 '<div ng-if="attached">' +
384 '<select ng-model="model">' + 384 '<select ng-model="model">' +
385 '<option value="a">foo</option>' + 385 '<option value="a">foo</option>' +
386 '<option value="b">bar</option>' + 386 '<option value="b">bar</option>' +
387 '</select>' + 387 '</select>' +
388 '</div>' + 388 '</div>' +
389 '</div>'); 389 '</div>');
390 _.rootScope.model = 'a'; 390 _.rootScope.context['model'] = 'b';
391 _.rootScope.attached = true; 391 _.rootScope.context['attached'] = true;
392 _.rootScope.$apply(); 392 _.rootScope.apply();
393 expect(_.rootElement).toEqualSelect([['a'], 'b']); 393 expect(_.rootElement).toEqualSelect(['a', ['b']]);
394 _.rootScope.attached = false; 394 _.rootScope.context['attached'] = false;
395 _.rootScope.$apply(); 395 _.rootScope.apply();
396 expect(_.rootElement).toEqualSelect([]); 396 expect(_.rootElement).toEqualSelect([]);
397 _.rootScope.attached = true; 397 _.rootScope.context['attached'] = true;
398 _.rootScope.$apply(); 398 _.rootScope.apply();
399 expect(_.rootElement).toEqualSelect([['a'], 'b']); 399 expect(_.rootElement).toEqualSelect(['a', ['b']]);
400 });
401
402
403 it('issue #428', () {
404 _.compile(
405 '<div>' +
406 '<div ng-if="attached">' +
407 '<select ng-model="model" multiple>' +
408 '<option value="a">foo</option>' +
409 '<option value="b">bar</option>' +
410 '</select>' +
411 '</div>' +
412 '</div>');
413 _.rootScope.context['model'] = ['b'];
414 _.rootScope.context['attached'] = true;
415 _.rootScope.apply();
416 expect(_.rootElement).toEqualSelect(['a', ['b']]);
417 _.rootScope.context['attached'] = false;
418 _.rootScope.apply();
419 expect(_.rootElement).toEqualSelect([]);
420 _.rootScope.context['attached'] = true;
421 _.rootScope.apply();
422 expect(_.rootElement).toEqualSelect(['a', ['b']]);
400 }); 423 });
401 }); 424 });
402 425
403 426
404 describe('select from angular.js', () { 427 describe('select from angular.js', () {
405 TestBed _; 428 TestBed _;
406 beforeEach(inject((TestBed tb) => _ = tb)); 429 beforeEach(inject((TestBed tb) => _ = tb));
407 430
408 var scope, formElement, element; 431 var scope, formElement, element;
409 432
410 compile(html) { 433 compile(html) {
411 _.compile('<form name="form">' + html + '</form>'); 434 _.compile('<form name="form">' + html + '</form>');
412 element = _.rootElement.querySelector('select'); 435 element = _.rootElement.querySelector('select');
413 scope.$apply(); 436 scope.apply();
414 } 437 }
415 438
416 beforeEach(inject((Scope rootScope) { 439 beforeEach(inject((Scope rootScope) {
417 scope = rootScope; 440 scope = rootScope;
418 formElement = element = null; 441 formElement = element = null;
419 })); 442 }));
420 443
421 444
422 afterEach(() { 445 afterEach(() {
423 scope.$destroy(); //disables unknown option work during destruction 446 scope.destroy(); //disables unknown option work during destruction
424 }); 447 });
425 448
426 449
427 describe('select-one', () { 450 describe('select-one', () {
428 451
429 it('should compile children of a select without a ngModel, but not creat e a model for it', 452 it('should compile children of a select without a ngModel, but not creat e a model for it',
430 () { 453 () {
431 compile('<select>' + 454 compile('<select>' +
432 '<option selected="true">{{a}}</option>' + 455 '<option selected="true">{{a}}</option>' +
433 '<option value="">{{b}}</option>' + 456 '<option value="">{{b}}</option>' +
434 '<option>C</option>' + 457 '<option>C</option>' +
435 '</select>'); 458 '</select>');
436 scope.$apply(() { 459 scope.apply(() {
437 scope.a = 'foo'; 460 scope.context['a'] = 'foo';
438 scope.b = 'bar'; 461 scope.context['b'] = 'bar';
439 }); 462 });
440 463
441 expect(element.text).toEqual('foobarC'); 464 expect(element.text).toEqual('foobarC');
442 }); 465 });
443 466
444 467
445 it('should not interfere with selection via selected attr if ngModel dir ective is not present', 468 it('should not interfere with selection via selected attr if ngModel dir ective is not present',
446 () { 469 () {
447 compile('<select>' + 470 compile('<select>' +
448 '<option>not me</option>' + 471 '<option>not me</option>' +
449 '<option selected>me!</option>' + 472 '<option selected>me!</option>' +
450 '<option>nah</option>' + 473 '<option>nah</option>' +
451 '</select>'); 474 '</select>');
452 expect(element).toEqualSelect(['not me', ['me!'], 'nah']); 475 expect(element).toEqualSelect(['not me', ['me!'], 'nah']);
453 }); 476 });
454 477
478 it('should fire ng-change event.', () {
479 var log = '';
480 compile(
481 '<select name="select" ng-model="selection" ng-change="change()">' +
482 '<option value=""></option>' +
483 '<option value="c">C</option>' +
484 '</select>');
485
486 scope.context['change'] = () {
487 log += 'change:${scope.context['selection']};';
488 };
489
490 scope.apply(() {
491 scope.context['selection'] = 'c';
492 });
493
494 element.value = 'c';
495 _.triggerEvent(element, 'change');
496 expect(log).toEqual('change:c;');
497 });
498
455 499
456 xit('should require', () { 500 xit('should require', () {
457 compile( 501 compile(
458 '<select name="select" ng-model="selection" required ng-change="chan ge()">' + 502 '<select name="select" ng-model="selection" required ng-change="chan ge()">' +
459 '<option value=""></option>' + 503 '<option value=""></option>' +
460 '<option value="c">C</option>' + 504 '<option value="c">C</option>' +
461 '</select>'); 505 '</select>');
462 506
463 scope.change = () { 507 scope.context['change'] = () {
464 scope.log += 'change;'; 508 scope.log += 'change;';
465 }; 509 };
466 510
467 scope.$apply(() { 511 scope.apply(() {
468 scope.log = ''; 512 scope.context['log'] = '';
469 scope.selection = 'c'; 513 scope.context['selection'] = 'c';
470 }); 514 });
471 515
472 expect(scope.form.select.$error.required).toEqual(false);; 516 expect(scope.context['form'].select.$error.required).toEqual(false);;
473 expect(element).toEqualValid(); 517 expect(element).toEqualValid();
474 expect(element).toEqualPristine(); 518 expect(element).toEqualPristine();
475 519
476 scope.$apply(() { 520 scope.apply(() {
477 scope.selection = ''; 521 scope.context['selection'] = '';
478 }); 522 });
479 523
480 expect(scope.form.select.$error.required).toEqual(true);; 524 expect(scope.context['form'].select.$error.required).toEqual(true);;
481 expect(element).toEqualInvalid(); 525 expect(element).toEqualInvalid();
482 expect(element).toEqualPristine(); 526 expect(element).toEqualPristine();
483 expect(scope.log).toEqual(''); 527 expect(scope.context['log']).toEqual('');
484 528
485 element[0].value = 'c'; 529 element[0].value = 'c';
486 _.triggerEvent(element, 'change'); 530 _.triggerEvent(element, 'change');
487 expect(element).toEqualValid(); 531 expect(element).toEqualValid();
488 expect(element).toEqualDirty(); 532 expect(element).toEqualDirty();
489 expect(scope.log).toEqual('change;'); 533 expect(scope.context['log']).toEqual('change;');
490 }); 534 });
491 535
492 536
493 xit('should not be invalid if no require', () { 537 xit('should not be invalid if no require', () {
494 compile( 538 compile(
495 '<select name="select" ng-model="selection">' + 539 '<select name="select" ng-model="selection">' +
496 '<option value=""></option>' + 540 '<option value=""></option>' +
497 '<option value="c">C</option>' + 541 '<option value="c">C</option>' +
498 '</select>'); 542 '</select>');
499 543
(...skipping 30 matching lines...) Expand all
530 574
531 describe('select-multiple', () { 575 describe('select-multiple', () {
532 576
533 it('should support type="select-multiple"', () { 577 it('should support type="select-multiple"', () {
534 compile( 578 compile(
535 '<select ng-model="selection" multiple>' + 579 '<select ng-model="selection" multiple>' +
536 '<option>A</option>' + 580 '<option>A</option>' +
537 '<option>B</option>' + 581 '<option>B</option>' +
538 '</select>'); 582 '</select>');
539 583
540 scope.$apply(() { 584 scope.apply(() {
541 scope.selection = ['A']; 585 scope.context['selection'] = ['A'];
542 }); 586 });
543 587
544 expect(element).toEqualSelect([['A'], 'B']); 588 expect(element).toEqualSelect([['A'], 'B']);
545 589
546 scope.$apply(() { 590 scope.apply(() {
547 scope.selection.add('B'); 591 scope.context['selection'].add('B');
548 }); 592 });
549 593
550 expect(element).toEqualSelect([['A'], ['B']]); 594 expect(element).toEqualSelect([['A'], ['B']]);
551 }); 595 });
552 596
553 it('should work with optgroups', () { 597 it('should work with optgroups', () {
554 compile('<select ng-model="selection" multiple>' + 598 compile('<select ng-model="selection" multiple>' +
555 '<optgroup label="group1">' + 599 '<optgroup label="group1">' +
556 '<option>A</option>' + 600 '<option>A</option>' +
557 '<option>B</option>' + 601 '<option>B</option>' +
558 '</optgroup>' + 602 '</optgroup>' +
559 '</select>'); 603 '</select>');
560 604
561 expect(element).toEqualSelect(['A', 'B']); 605 expect(element).toEqualSelect(['A', 'B']);
562 expect(scope.selection).toEqual(null); 606 expect(scope.context['selection']).toEqual(null);
563 607
564 scope.$apply(() { 608 scope.apply(() {
565 scope.selection = ['A']; 609 scope.context['selection'] = ['A'];
566 }); 610 });
567 expect(element).toEqualSelect([['A'], 'B']); 611 expect(element).toEqualSelect([['A'], 'B']);
568 612
569 scope.$apply(() { 613 scope.apply(() {
570 scope.selection.add('B'); 614 scope.context['selection'].add('B');
571 }); 615 });
572 expect(element).toEqualSelect([['A'], ['B']]); 616 expect(element).toEqualSelect([['A'], ['B']]);
573 }); 617 });
574 618
575 xit('should require', () { 619 xit('should require', () {
576 compile( 620 compile(
577 '<select name="select" ng-model="selection" multiple required>' + 621 '<select name="select" ng-model="selection" multiple required>' +
578 '<option>A</option>' + 622 '<option>A</option>' +
579 '<option>B</option>' + 623 '<option>B</option>' +
580 '</select>'); 624 '</select>');
581 625
582 scope.$apply(() { 626 scope.apply(() {
583 scope.selection = []; 627 scope.context['selection'] = [];
584 }); 628 });
585 629
586 expect(scope.form.select.$error.required).toEqual(true);; 630 expect(scope.context['form'].select.$error.required).toEqual(true);;
587 expect(element).toEqualInvalid(); 631 expect(element).toEqualInvalid();
588 expect(element).toEqualPristine(); 632 expect(element).toEqualPristine();
589 633
590 scope.$apply(() { 634 scope.apply(() {
591 scope.selection = ['A']; 635 scope.context['selection'] = ['A'];
592 }); 636 });
593 637
594 expect(element).toEqualValid(); 638 expect(element).toEqualValid();
595 expect(element).toEqualPristine(); 639 expect(element).toEqualPristine();
596 640
597 element[0].value = 'B'; 641 element[0].value = 'B';
598 _.triggerEvent(element, 'change'); 642 _.triggerEvent(element, 'change');
599 expect(element).toEqualValid(); 643 expect(element).toEqualValid();
600 expect(element).toEqualDirty(); 644 expect(element).toEqualDirty();
601 }); 645 });
(...skipping 29 matching lines...) Expand all
631 createSelect({ 675 createSelect({
632 'ng-model':'selected', 676 'ng-model':'selected',
633 'multiple':true 677 'multiple':true
634 }, blank, unknown, 'value in values', 'value.name', 'value'); 678 }, blank, unknown, 'value in values', 'value.name', 'value');
635 } 679 }
636 680
637 681
638 it('should render a list', () { 682 it('should render a list', () {
639 createSingleSelect(); 683 createSingleSelect();
640 684
641 scope.$apply(() { 685 scope.apply(() {
642 scope.values = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}]; 686 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}, {'name': 'C '}];
643 scope.selected = scope.values[0]; 687 scope.context['selected'] = scope.context['values'][0];
644 }); 688 });
645 689
646 var options = element.querySelectorAll('option'); 690 var options = element.querySelectorAll('option');
647 expect(options.length).toEqual(3); 691 expect(options.length).toEqual(3);
648 expect(element).toEqualSelect([['A'], 'B', 'C']); 692 expect(element).toEqualSelect([['A'], 'B', 'C']);
649 }); 693 });
650 694
651 it('should render zero as a valid display value', () { 695 it('should render zero as a valid display value', () {
652 createSingleSelect(); 696 createSingleSelect();
653 697
654 scope.$apply(() { 698 scope.apply(() {
655 scope.values = [{'name': '0'}, {'name': '1'}, {'name': '2'}]; 699 scope.context['values'] = [{'name': '0'}, {'name': '1'}, {'name': '2 '}];
656 scope.selected = scope.values[0]; 700 scope.context['selected'] = scope.context['values'][0];
657 }); 701 });
658 702
659 var options = element.querySelectorAll('option'); 703 var options = element.querySelectorAll('option');
660 expect(options.length).toEqual(3); 704 expect(options.length).toEqual(3);
661 expect(element).toEqualSelect([['0'], '1', '2']); 705 expect(element).toEqualSelect([['0'], '1', '2']);
662 }); 706 });
663 707
664 it('should grow list', () { 708 it('should grow list', () {
665 createSingleSelect(); 709 createSingleSelect();
666 710
667 scope.$apply(() { 711 scope.apply(() {
668 scope.values = []; 712 scope.context['values'] = [];
669 }); 713 });
670 714
671 expect(element.querySelectorAll('option').length).toEqual(1); // becau se we add special empty option 715 expect(element.querySelectorAll('option').length).toEqual(1); // becau se we add special empty option
672 expect(element.querySelectorAll('option')[0].text).toEqual(''); 716 expect(element.querySelectorAll('option')[0].text).toEqual('');
673 expect(element.querySelectorAll('option')[0].value).toEqual('?'); 717 expect(element.querySelectorAll('option')[0].value).toEqual('?');
674 718
675 scope.$apply(() { 719 scope.apply(() {
676 scope.values.add({'name':'A'}); 720 scope.context['values'].add({'name':'A'});
677 scope.selected = scope.values[0]; 721 scope.context['selected'] = scope.context['values'][0];
678 }); 722 });
679 723
680 expect(element.querySelectorAll('option').length).toEqual(1); 724 expect(element.querySelectorAll('option').length).toEqual(1);
681 expect(element).toEqualSelect([['A']]); 725 expect(element).toEqualSelect([['A']]);
682 726
683 scope.$apply(() { 727 scope.apply(() {
684 scope.values.add({'name':'B'}); 728 scope.context['values'].add({'name':'B'});
685 }); 729 });
686 730
687 expect(element.querySelectorAll('option').length).toEqual(2); 731 expect(element.querySelectorAll('option').length).toEqual(2);
688 expect(element).toEqualSelect([['A'], 'B']); 732 expect(element).toEqualSelect([['A'], 'B']);
689 }); 733 });
690 734
691 735
692 it('should shrink list', () { 736 it('should shrink list', () {
693 createSingleSelect(); 737 createSingleSelect();
694 738
695 scope.$apply(() { 739 scope.apply(() {
696 scope.values = [{'name':'A'}, {'name':'B'}, {'name':'C'}]; 740 scope.context['values'] = [{'name':'A'}, {'name':'B'}, {'name':'C'}] ;
697 scope.selected = scope.values[0]; 741 scope.context['selected'] = scope.context['values'][0];
698 }); 742 });
699 743
700 expect(element.querySelectorAll('option').length).toEqual(3); 744 expect(element.querySelectorAll('option').length).toEqual(3);
701 745
702 scope.$apply(() { 746 scope.apply(() {
703 scope.values.removeLast(); 747 scope.context['values'].removeLast();
704 }); 748 });
705 749
706 expect(element.querySelectorAll('option').length).toEqual(2); 750 expect(element.querySelectorAll('option').length).toEqual(2);
707 expect(element).toEqualSelect([['A'], 'B']); 751 expect(element).toEqualSelect([['A'], 'B']);
708 752
709 scope.$apply(() { 753 scope.apply(() {
710 scope.values.removeLast(); 754 scope.context['values'].removeLast();
711 }); 755 });
712 756
713 expect(element.querySelectorAll('option').length).toEqual(1); 757 expect(element.querySelectorAll('option').length).toEqual(1);
714 expect(element).toEqualSelect([['A']]); 758 expect(element).toEqualSelect([['A']]);
715 759
716 scope.$apply(() { 760 scope.apply(() {
717 scope.values.removeLast(); 761 scope.context['values'].removeLast();
718 scope.selected = null; 762 scope.context['selected'] = null;
719 }); 763 });
720 764
721 expect(element.querySelectorAll('option').length).toEqual(1); // we ad d back the special empty option 765 expect(element.querySelectorAll('option').length).toEqual(1); // we ad d back the special empty option
722 }); 766 });
723 767
724 768
725 it('should shrink and then grow list', () { 769 it('should shrink and then grow list', () {
726 createSingleSelect(); 770 createSingleSelect();
727 771
728 scope.$apply(() { 772 scope.apply(() {
729 scope.values = [{'name':'A'}, {'name':'B'}, {'name':'C'}]; 773 scope.context['values'] = [{'name':'A'}, {'name':'B'}, {'name':'C'}] ;
730 scope.selected = scope.values[0]; 774 scope.context['selected'] = scope.context['values'][0];
731 }); 775 });
732 776
733 expect(element.querySelectorAll('option').length).toEqual(3); 777 expect(element.querySelectorAll('option').length).toEqual(3);
734 778
735 scope.$apply(() { 779 scope.apply(() {
736 scope.values = [{'name': '1'}, {'name': '2'}]; 780 scope.context['values'] = [{'name': '1'}, {'name': '2'}];
737 scope.selected = scope.values[0]; 781 scope.context['selected'] = scope.context['values'][0];
738 }); 782 });
739 783
740 expect(element.querySelectorAll('option').length).toEqual(2); 784 expect(element.querySelectorAll('option').length).toEqual(2);
741 785
742 scope.$apply(() { 786 scope.apply(() {
743 scope.values = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}]; 787 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}, {'name': 'C '}];
744 scope.selected = scope.values[0]; 788 scope.context['selected'] = scope.context['values'][0];
745 }); 789 });
746 790
747 expect(element.querySelectorAll('option').length).toEqual(3); 791 expect(element.querySelectorAll('option').length).toEqual(3);
748 }); 792 });
749 793
750 794
751 it('should update list', () { 795 it('should update list', () {
752 createSingleSelect(); 796 createSingleSelect();
753 797
754 scope.$apply(() { 798 scope.apply(() {
755 scope.values = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}]; 799 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}, {'name': 'C '}];
756 scope.selected = scope.values[0]; 800 scope.context['selected'] = scope.context['values'][0];
757 }); 801 });
758 expect(element).toEqualSelect([['A'], 'B', 'C']); 802 expect(element).toEqualSelect([['A'], 'B', 'C']);
759 scope.$apply(() { 803 scope.apply(() {
760 scope.values = [{'name': 'B'}, {'name': 'C'}, {'name': 'D'}]; 804 scope.context['values'] = [{'name': 'B'}, {'name': 'C'}, {'name': 'D '}];
761 scope.selected = scope.values[0]; 805 scope.context['selected'] = scope.context['values'][0];
762 }); 806 });
763 807
764 var options = element.querySelectorAll('option'); 808 var options = element.querySelectorAll('option');
765 expect(options.length).toEqual(3); 809 expect(options.length).toEqual(3);
766 expect(element).toEqualSelect([['B'], 'C', 'D']); 810 expect(element).toEqualSelect([['B'], 'C', 'D']);
767 }); 811 });
768 812
769 813
770 it('should preserve existing options', () { 814 it('should preserve existing options', () {
771 createSingleSelect(true); 815 createSingleSelect(true);
772 816
773 scope.$apply(() { 817 scope.apply(() {
774 scope.values = []; 818 scope.context['values'] = [];
775 }); 819 });
776 820
777 expect(element.querySelectorAll('option').length).toEqual(1); 821 expect(element.querySelectorAll('option').length).toEqual(1);
778 822
779 scope.$apply(() { 823 scope.apply(() {
780 scope.values = [{'name': 'A'}]; 824 scope.context['values'] = [{'name': 'A'}];
781 scope.selected = scope.values[0]; 825 scope.context['selected'] = scope.context['values'][0];
782 }); 826 });
783 827
784 expect(element.querySelectorAll('option').length).toEqual(2); 828 expect(element.querySelectorAll('option').length).toEqual(2);
785 expect(element.querySelectorAll('option')[0].text).toEqual('blank'); 829 expect(element.querySelectorAll('option')[0].text).toEqual('blank');
786 expect(element.querySelectorAll('option')[1].text).toEqual('A'); 830 expect(element.querySelectorAll('option')[1].text).toEqual('A');
787 831
788 scope.$apply(() { 832 scope.apply(() {
789 scope.values = []; 833 scope.context['values'] = [];
790 scope.selected = null; 834 scope.context['selected'] = null;
791 }); 835 });
792 836
793 expect(element.querySelectorAll('option').length).toEqual(1); 837 expect(element.querySelectorAll('option').length).toEqual(1);
794 expect(element.querySelectorAll('option')[0].text).toEqual('blank'); 838 expect(element.querySelectorAll('option')[0].text).toEqual('blank');
795 }); 839 });
796 840
797 describe('binding', () { 841 describe('binding', () {
798 842
799 it('should bind to scope value', () { 843 it('should bind to scope value', () {
800 createSingleSelect(); 844 createSingleSelect();
801 845
802 scope.$apply(() { 846 scope.apply(() {
803 scope.values = [{'name': 'A'}, {'name': 'B'}]; 847 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}];
804 scope.selected = scope.values[0]; 848 scope.context['selected'] = scope.context['values'][0];
805 }); 849 });
806 850
807 expect(element).toEqualSelect([['A'], 'B']); 851 expect(element).toEqualSelect([['A'], 'B']);
808 852
809 scope.$apply(() { 853 scope.apply(() {
810 scope.selected = scope.values[1]; 854 scope.context['selected'] = scope.context['values'][1];
811 }); 855 });
812 856
813 expect(element).toEqualSelect(['A', ['B']]); 857 expect(element).toEqualSelect(['A', ['B']]);
814 }); 858 });
815 859
816 860
817 // TODO(misko): re-enable once we support group by 861 // TODO(misko): re-enable once we support group by
818 xit('should bind to scope value and group', () { 862 xit('should bind to scope value and group', () {
819 createSelect({ 863 createSelect({
820 'ng-model': 'selected', 864 'ng-model': 'selected',
821 'ng-options': 'item.name group by item.group for item in values' 865 'ng-options': 'item.name group by item.group for item in values'
822 }); 866 });
823 867
824 scope.$apply(() { 868 scope.apply(() {
825 scope.values = [{'name': 'A'}, 869 scope.context['values'] = [{'name': 'A'},
826 {'name': 'B', group: 'first'}, 870 {'name': 'B', group: 'first'},
827 {'name': 'C', group: 'second'}, 871 {'name': 'C', group: 'second'},
828 {'name': 'D', group: 'first'}, 872 {'name': 'D', group: 'first'},
829 {'name': 'E', group: 'second'}]; 873 {'name': 'E', group: 'second'}];
830 scope.selected = scope.values[3]; 874 scope.context['selected'] = scope.context['values'][3];
831 }); 875 });
832 876
833 expect(element).toEqualSelect(['A', 'B', ['D'], 'C', 'E']); 877 expect(element).toEqualSelect(['A', 'B', ['D'], 'C', 'E']);
834 878
835 var first = element.querySelectorAll('optgroup')[0]; 879 var first = element.querySelectorAll('optgroup')[0];
836 var b = first.querySelectorAll('option')[0]; 880 var b = first.querySelectorAll('option')[0];
837 var d = first.querySelectorAll('option')[1]; 881 var d = first.querySelectorAll('option')[1];
838 expect(first.attr('label')).toEqual('first'); 882 expect(first.attr('label')).toEqual('first');
839 expect(b.text).toEqual('B'); 883 expect(b.text).toEqual('B');
840 expect(d.text).toEqual('D'); 884 expect(d.text).toEqual('D');
841 885
842 var second = element.querySelectorAll('optgroup')[1]; 886 var second = element.querySelectorAll('optgroup')[1];
843 var c = second.querySelectorAll('option')[0]; 887 var c = second.querySelectorAll('option')[0];
844 var e = second.querySelectorAll('option')[1]; 888 var e = second.querySelectorAll('option')[1];
845 expect(second.attr('label')).toEqual('second'); 889 expect(second.attr('label')).toEqual('second');
846 expect(c.text).toEqual('C'); 890 expect(c.text).toEqual('C');
847 expect(e.text).toEqual('E'); 891 expect(e.text).toEqual('E');
848 892
849 scope.$apply(() { 893 scope.apply(() {
850 scope.selected = scope.values[0]; 894 scope.context['selected'] = scope.context['values'][0];
851 }); 895 });
852 896
853 expect(element.value).toEqual('0'); 897 expect(element.value).toEqual('0');
854 }); 898 });
855 899
856 900
857 it('should bind to scope value through experession', () { 901 it('should bind to scope value through experession', () {
858 createSelect({'ng-model': 'selected'}, null, null, 'item in values', 'item.name', 'item.id'); 902 createSelect({'ng-model': 'selected'}, null, null, 'item in values', 'item.name', 'item.id');
859 903
860 scope.$apply(() { 904 scope.apply(() {
861 scope.values = [{'id': 10, 'name': 'A'}, {'id': 20, 'name': 'B'}]; 905 scope.context['values'] = [{'id': 10, 'name': 'A'}, {'id': 20, 'na me': 'B'}];
862 scope.selected = scope.values[0]['id']; 906 scope.context['selected'] = scope.context['values'][0]['id'];
863 }); 907 });
864 908
865 expect(element).toEqualSelect([['A'], 'B']); 909 expect(element).toEqualSelect([['A'], 'B']);
866 910
867 scope.$apply(() { 911 scope.apply(() {
868 scope.selected = scope.values[1]['id']; 912 scope.context['selected'] = scope.context['values'][1]['id'];
869 }); 913 });
870 914
871 expect(element).toEqualSelect(['A', ['B']]); 915 expect(element).toEqualSelect(['A', ['B']]);
872 }); 916 });
873 917
874 918
875 it('should insert a blank option if bound to null', () { 919 it('should insert a blank option if bound to null', () {
876 createSingleSelect(); 920 createSingleSelect();
877 921
878 scope.$apply(() { 922 scope.apply(() {
879 scope.values = [{'name': 'A'}]; 923 scope.context['values'] = [{'name': 'A'}];
880 scope.selected = null; 924 scope.context['selected'] = null;
881 }); 925 });
882 926
883 expect(element.querySelectorAll('option').length).toEqual(2); 927 expect(element.querySelectorAll('option').length).toEqual(2);
884 expect(element).toEqualSelect([['?'], 'A']); 928 expect(element).toEqualSelect([['?'], 'A']);
885 expect(element.querySelectorAll('option')[0].value).toEqual('?'); 929 expect(element.querySelectorAll('option')[0].value).toEqual('?');
886 930
887 scope.$apply(() { 931 scope.apply(() {
888 scope.selected = scope.values[0]; 932 scope.context['selected'] = scope.context['values'][0];
889 }); 933 });
890 934
891 expect(element).toEqualSelect([['A']]); 935 expect(element).toEqualSelect([['A']]);
892 expect(element.querySelectorAll('option').length).toEqual(1); 936 expect(element.querySelectorAll('option').length).toEqual(1);
893 }); 937 });
894 938
895 939
896 it('should reuse blank option if bound to null', () { 940 it('should reuse blank option if bound to null', () {
897 createSingleSelect(true); 941 createSingleSelect(true);
898 942
899 scope.$apply(() { 943 scope.apply(() {
900 scope.values = [{'name': 'A'}]; 944 scope.context['values'] = [{'name': 'A'}];
901 scope.selected = null; 945 scope.context['selected'] = null;
902 }); 946 });
903 947
904 expect(element.querySelectorAll('option').length).toEqual(2); 948 expect(element.querySelectorAll('option').length).toEqual(2);
905 expect(element.value).toEqual(''); 949 expect(element.value).toEqual('');
906 expect(element.querySelectorAll('option')[0].value).toEqual(''); 950 expect(element.querySelectorAll('option')[0].value).toEqual('');
907 951
908 scope.$apply(() { 952 scope.apply(() {
909 scope.selected = scope.values[0]; 953 scope.context['selected'] = scope.context['values'][0];
910 }); 954 });
911 955
912 expect(element).toEqualSelect(['', ['A']]); 956 expect(element).toEqualSelect(['', ['A']]);
913 expect(element.querySelectorAll('option').length).toEqual(2); 957 expect(element.querySelectorAll('option').length).toEqual(2);
914 }); 958 });
915 959
916 960
917 it('should insert a unknown option if bound to something not in the li st', () { 961 it('should insert a unknown option if bound to something not in the li st', () {
918 createSingleSelect(); 962 createSingleSelect();
919 963
920 scope.$apply(() { 964 scope.apply(() {
921 scope.values = [{'name': 'A'}]; 965 scope.context['values'] = [{'name': 'A'}];
922 scope.selected = {}; 966 scope.context['selected'] = {};
923 }); 967 });
924 968
925 expect(element.querySelectorAll('option').length).toEqual(2); 969 expect(element.querySelectorAll('option').length).toEqual(2);
926 expect(element.value).toEqual('?'); 970 expect(element.value).toEqual('?');
927 expect(element.querySelectorAll('option')[0].value).toEqual('?'); 971 expect(element.querySelectorAll('option')[0].value).toEqual('?');
928 972
929 scope.$apply(() { 973 scope.apply(() {
930 scope.selected = scope.values[0]; 974 scope.context['selected'] = scope.context['values'][0];
931 }); 975 });
932 976
933 expect(element).toEqualSelect([['A']]); 977 expect(element).toEqualSelect([['A']]);
934 expect(element.querySelectorAll('option').length).toEqual(1); 978 expect(element.querySelectorAll('option').length).toEqual(1);
935 }); 979 });
936 980
937 981
938 it('should select correct input if previously selected option was "?"' , () { 982 it('should select correct input if previously selected option was "?"' , () {
939 createSingleSelect(); 983 createSingleSelect();
940 984
941 scope.$apply(() { 985 scope.apply(() {
942 scope.values = [{'name': 'A'}, {'name': 'B'}]; 986 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}];
943 scope.selected = {}; 987 scope.context['selected'] = {};
944 }); 988 });
945 989
946 expect(element.querySelectorAll('option').length).toEqual(3); 990 expect(element.querySelectorAll('option').length).toEqual(3);
947 expect(element.value).toEqual('?'); 991 expect(element.value).toEqual('?');
948 expect(element.querySelectorAll('option')[0].value).toEqual('?'); 992 expect(element.querySelectorAll('option')[0].value).toEqual('?');
949 993
950 _.selectOption(element, 'A'); 994 _.selectOption(element, 'A');
951 expect(scope.selected).toBe(scope.values[0]); 995 expect(scope.context['selected']).toBe(scope.context['values'][0]);
952 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ; 996 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;
953 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;; 997 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;;
954 expect(element.querySelectorAll('option').length).toEqual(2); 998 expect(element.querySelectorAll('option').length).toEqual(2);
955 }); 999 });
956 }); 1000 });
957 1001
958 1002
959 describe('blank option', () { 1003 describe('blank option', () {
960 1004
961 it('should be compiled as template, be watched and updated', () { 1005 it('should be compiled as template, be watched and updated', () {
962 var option; 1006 var option;
963 createSingleSelect('<option value="">blank is {{blankVal}}</option>' ); 1007 createSingleSelect('<option value="">blank is {{blankVal}}</option>' );
964 1008
965 scope.$apply(() { 1009 scope.apply(() {
966 scope.blankVal = 'so blank'; 1010 scope.context['blankVal'] = 'so blank';
967 scope.values = [{'name': 'A'}]; 1011 scope.context['values'] = [{'name': 'A'}];
968 }); 1012 });
969 1013
970 // check blank option is first and is compiled 1014 // check blank option is first and is compiled
971 expect(element.querySelectorAll('option').length).toEqual(2); 1015 expect(element.querySelectorAll('option').length).toEqual(2);
972 option = element.querySelectorAll('option')[0]; 1016 option = element.querySelectorAll('option')[0];
973 expect(option.value).toEqual(''); 1017 expect(option.value).toEqual('');
974 expect(option.text).toEqual('blank is so blank'); 1018 expect(option.text).toEqual('blank is so blank');
975 1019
976 scope.$apply(() { 1020 scope.apply(() {
977 scope.blankVal = 'not so blank'; 1021 scope.context['blankVal'] = 'not so blank';
978 }); 1022 });
979 1023
980 // check blank option is first and is compiled 1024 // check blank option is first and is compiled
981 expect(element.querySelectorAll('option').length).toEqual(2); 1025 expect(element.querySelectorAll('option').length).toEqual(2);
982 option = element.querySelectorAll('option')[0]; 1026 option = element.querySelectorAll('option')[0];
983 expect(option.value).toEqual(''); 1027 expect(option.value).toEqual('');
984 expect(option.text).toEqual('blank is not so blank'); 1028 expect(option.text).toEqual('blank is not so blank');
985 }); 1029 });
986 1030
987 1031
988 it('should support binding via ngBindTemplate directive', () { 1032 it('should support binding via ngBindTemplate directive', () {
989 var option; 1033 var option;
990 createSingleSelect('<option value="" ng-bind="\'blank is \' + blankV al"></option>'); 1034 createSingleSelect('<option value="" ng-bind="\'blank is \' + blankV al"></option>');
991 1035
992 scope.$apply(() { 1036 scope.apply(() {
993 scope.blankVal = 'so blank'; 1037 scope.context['blankVal'] = 'so blank';
994 scope.values = [{'name': 'A'}]; 1038 scope.context['values'] = [{'name': 'A'}];
995 }); 1039 });
996 1040
997 // check blank option is first and is compiled 1041 // check blank option is first and is compiled
998 expect(element.querySelectorAll('option').length).toEqual(2); 1042 expect(element.querySelectorAll('option').length).toEqual(2);
999 option = element.querySelectorAll('option')[0]; 1043 option = element.querySelectorAll('option')[0];
1000 expect(option.value).toEqual(''); 1044 expect(option.value).toEqual('');
1001 expect(option.text).toEqual('blank is so blank'); 1045 expect(option.text).toEqual('blank is so blank');
1002 }); 1046 });
1003 1047
1004 1048
1005 it('should support biding via ngBind attribute', () { 1049 it('should support biding via ngBind attribute', () {
1006 var option; 1050 var option;
1007 createSingleSelect('<option value="" ng-bind="blankVal"></option>'); 1051 createSingleSelect('<option value="" ng-bind="blankVal"></option>');
1008 1052
1009 scope.$apply(() { 1053 scope.apply(() {
1010 scope.blankVal = 'is blank'; 1054 scope.context['blankVal'] = 'is blank';
1011 scope.values = [{'name': 'A'}]; 1055 scope.context['values'] = [{'name': 'A'}];
1012 }); 1056 });
1013 1057
1014 // check blank option is first and is compiled 1058 // check blank option is first and is compiled
1015 expect(element.querySelectorAll('option').length).toEqual(2); 1059 expect(element.querySelectorAll('option').length).toEqual(2);
1016 option = element.querySelectorAll('option')[0]; 1060 option = element.querySelectorAll('option')[0];
1017 expect(option.value).toEqual(''); 1061 expect(option.value).toEqual('');
1018 expect(option.text).toEqual('is blank'); 1062 expect(option.text).toEqual('is blank');
1019 }); 1063 });
1020 1064
1021 1065
1022 it('should be rendered with the attributes preserved', () { 1066 it('should be rendered with the attributes preserved', () {
1023 var option; 1067 var option;
1024 createSingleSelect('<option value="" class="coyote" id="road-runner" ' + 1068 createSingleSelect('<option value="" class="coyote" id="road-runner" ' +
1025 'custom-attr="custom-attr">{{blankVal}}</option>'); 1069 'custom-attr="custom-attr">{{blankVal}}</option>');
1026 1070
1027 scope.$apply(() { 1071 scope.apply(() {
1028 scope.blankVal = 'is blank'; 1072 scope.context['blankVal'] = 'is blank';
1029 }); 1073 });
1030 1074
1031 // check blank option is first and is compiled 1075 // check blank option is first and is compiled
1032 option = element.querySelectorAll('option')[0]; 1076 option = element.querySelectorAll('option')[0];
1033 expect(option.classes.contains('coyote')).toEqual(true);; 1077 expect(option.classes.contains('coyote')).toEqual(true);;
1034 expect(option.attributes['id']).toEqual('road-runner'); 1078 expect(option.attributes['id']).toEqual('road-runner');
1035 expect(option.attributes['custom-attr']).toEqual('custom-attr'); 1079 expect(option.attributes['custom-attr']).toEqual('custom-attr');
1036 }); 1080 });
1037 1081
1038 it('should be selected, if it is available and no other option is sele cted', () { 1082 it('should be selected, if it is available and no other option is sele cted', () {
1039 // selectedIndex is used here because $ incorrectly reports element. value 1083 // selectedIndex is used here because $ incorrectly reports element. value
1040 scope.$apply(() { 1084 scope.apply(() {
1041 scope.values = [{'name': 'A'}]; 1085 scope.context['values'] = [{'name': 'A'}];
1042 }); 1086 });
1043 createSingleSelect(true); 1087 createSingleSelect(true);
1044 // ensure the first option (the blank option) is selected 1088 // ensure the first option (the blank option) is selected
1045 expect(element.selectedIndex).toEqual(0); 1089 expect(element.selectedIndex).toEqual(0);
1046 scope.$digest(); 1090 scope.apply();
1047 // ensure the option has not changed following the digest 1091 // ensure the option has not changed following the digest
1048 expect(element.selectedIndex).toEqual(0); 1092 expect(element.selectedIndex).toEqual(0);
1049 }); 1093 });
1050 }); 1094 });
1051 1095
1052 1096
1053 describe('on change', () { 1097 describe('on change', () {
1054 1098
1055 it('should update model on change', () { 1099 it('should update model on change', () {
1056 createSingleSelect(); 1100 createSingleSelect();
1057 1101
1058 scope.$apply(() { 1102 scope.apply(() {
1059 scope.values = [{'name': 'A'}, {'name': 'B'}]; 1103 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}];
1060 scope.selected = scope.values[0]; 1104 scope.context['selected'] = scope.context['values'][0];
1061 }); 1105 });
1062 1106
1063 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ; 1107 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;
1064 1108
1065 element.querySelectorAll('option')[1].selected = true; 1109 element.querySelectorAll('option')[1].selected = true;
1066 _.triggerEvent(element, 'change'); 1110 _.triggerEvent(element, 'change');
1067 expect(scope.selected).toEqual(scope.values[1]); 1111 expect(scope.context['selected']).toEqual(scope.context['values'][1] );
1068 }); 1112 });
1069 1113
1070 1114
1071 it('should update model on change through expression', () { 1115 it('should update model on change through expression', () {
1072 createSelect({'ng-model': 'selected'}, null, null, 1116 createSelect({'ng-model': 'selected'}, null, null,
1073 'item in values', 'item.name', 'item.id'); 1117 'item in values', 'item.name', 'item.id');
1074 1118
1075 scope.$apply(() { 1119 scope.apply(() {
1076 scope.values = [{'id': 10, 'name': 'A'}, {'id': 20, 'name': 'B'}]; 1120 scope.context['values'] = [{'id': 10, 'name': 'A'}, {'id': 20, 'na me': 'B'}];
1077 scope.selected = scope.values[0]['id']; 1121 scope.context['selected'] = scope.context['values'][0]['id'];
1078 }); 1122 });
1079 1123
1080 expect(element).toEqualSelect([['A'], 'B']); 1124 expect(element).toEqualSelect([['A'], 'B']);
1081 1125
1082 element.querySelectorAll('option')[1].selected = true; 1126 element.querySelectorAll('option')[1].selected = true;
1083 _.triggerEvent(element, 'change'); 1127 _.triggerEvent(element, 'change');
1084 expect(scope.selected).toEqual(scope.values[1]['id']); 1128 expect(scope.context['selected']).toEqual(scope.context['values'][1] ['id']);
1085 }); 1129 });
1086 1130
1087 1131
1088 it('should update model to null on change', () { 1132 it('should update model to null on change', () {
1089 createSingleSelect(true); 1133 createSingleSelect(true);
1090 1134
1091 scope.$apply(() { 1135 scope.apply(() {
1092 scope.values = [{'name': 'A'}, {'name': 'B'}]; 1136 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}];
1093 scope.selected = scope.values[0]; 1137 scope.context['selected'] = scope.context['values'][0];
1094 element.value = '0'; 1138 element.value = '0';
1095 }); 1139 });
1096 1140
1097 _.selectOption(element, 'blank'); 1141 _.selectOption(element, 'blank');
1098 expect(element).toEqualSelect([[''], 'A', 'B']); 1142 expect(element).toEqualSelect([[''], 'A', 'B']);
1099 1143
1100 expect(scope.selected).toEqual(null); 1144 expect(scope.context['selected']).toEqual(null);
1101 }); 1145 });
1102 }); 1146 });
1103 1147
1104 1148
1105 describe('select-many', () { 1149 describe('select-many', () {
1106 1150
1107 it('should read multiple selection', () { 1151 it('should read multiple selection', () {
1108 createMultiSelect(); 1152 createMultiSelect();
1109 1153
1110 scope.$apply(() { 1154 scope.apply(() {
1111 scope.values = [{'name': 'A'}, {'name': 'B'}]; 1155 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}];
1112 scope.selected = []; 1156 scope.context['selected'] = [];
1113 }); 1157 });
1114 1158
1115 expect(element.querySelectorAll('option').length).toEqual(2); 1159 expect(element.querySelectorAll('option').length).toEqual(2);
1116 expect(element.querySelectorAll('option')[0].selected).toEqual(false );; 1160 expect(element.querySelectorAll('option')[0].selected).toEqual(false );;
1117 expect(element.querySelectorAll('option')[1].selected).toEqual(false );; 1161 expect(element.querySelectorAll('option')[1].selected).toEqual(false );;
1118 1162
1119 scope.$apply(() { 1163 scope.apply(() {
1120 scope.selected.add(scope.values[1]); 1164 scope.context['selected'].add(scope.context['values'][1]);
1121 }); 1165 });
1122 1166
1123 expect(element.querySelectorAll('option').length).toEqual(2); 1167 expect(element.querySelectorAll('option').length).toEqual(2);
1124 expect(element.querySelectorAll('option')[0].selected).toEqual(false );; 1168 expect(element.querySelectorAll('option')[0].selected).toEqual(false );;
1125 expect(element.querySelectorAll('option')[1].selected).toEqual(true) ;; 1169 expect(element.querySelectorAll('option')[1].selected).toEqual(true) ;;
1126 1170
1127 scope.$apply(() { 1171 scope.apply(() {
1128 scope.selected.add(scope.values[0]); 1172 scope.context['selected'].add(scope.context['values'][0]);
1129 }); 1173 });
1130 1174
1131 expect(element.querySelectorAll('option').length).toEqual(2); 1175 expect(element.querySelectorAll('option').length).toEqual(2);
1132 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;; 1176 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;;
1133 expect(element.querySelectorAll('option')[1].selected).toEqual(true) ;; 1177 expect(element.querySelectorAll('option')[1].selected).toEqual(true) ;;
1134 }); 1178 });
1135 1179
1136 1180
1137 it('should update model on change', () { 1181 it('should update model on change', () {
1138 createMultiSelect(); 1182 createMultiSelect();
1139 1183
1140 scope.$apply(() { 1184 scope.apply(() {
1141 scope.values = [{'name': 'A'}, {'name': 'B'}]; 1185 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}];
1142 scope.selected = []; 1186 scope.context['selected'] = [];
1143 }); 1187 });
1144 1188
1145 element.querySelectorAll('option')[0].selected = true; 1189 element.querySelectorAll('option')[0].selected = true;
1146 1190
1147 _.triggerEvent(element, 'change'); 1191 _.triggerEvent(element, 'change');
1148 expect(scope.selected).toEqual([scope.values[0]]); 1192 expect(scope.context['selected']).toEqual([scope.context['values'][0 ]]);
1149 }); 1193 });
1150 1194
1151 1195
1152 it('should deselect all options when model is emptied', () { 1196 it('should deselect all options when model is emptied', () {
1153 createMultiSelect(); 1197 createMultiSelect();
1154 scope.$apply(() { 1198 scope.apply(() {
1155 scope.values = [{'name': 'A'}, {'name': 'B'}]; 1199 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}];
1156 scope.selected = [scope.values[0]]; 1200 scope.context['selected'] = [scope.context['values'][0]];
1157 }); 1201 });
1158 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ; 1202 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;
1159 1203
1160 scope.$apply(() { 1204 scope.apply(() {
1161 scope.selected.removeLast(); 1205 scope.context['selected'].removeLast();
1162 }); 1206 });
1163 1207
1164 expect(element.querySelectorAll('option')[0].selected).toEqual(false ); 1208 expect(element.querySelectorAll('option')[0].selected).toEqual(false );
1165 }); 1209 });
1166 }); 1210 });
1167 1211
1168 1212
1169 xdescribe('ngRequired', () { 1213 xdescribe('ngRequired', () {
1170 1214
1171 it('should allow bindings on ngRequired', () { 1215 it('should allow bindings on ngRequired', () {
1172 createSelect({ 1216 createSelect({
1173 'ng-model': 'value', 1217 'ng-model': 'value',
1174 'ng-options': 'item.name for item in values', 1218 'ng-options': 'item.name for item in values',
1175 'ng-required': 'required' 1219 'ng-required': 'required'
1176 }, true); 1220 }, true);
1177 1221
1178 1222
1179 scope.$apply(() { 1223 scope.apply(() {
1180 scope.values = [{'name': 'A', 'id': 1}, {'name': 'B', 'id': 2}]; 1224 scope.context['values'] = [{'name': 'A', 'id': 1}, {'name': 'B', ' id': 2}];
1181 scope.required = false; 1225 scope.context['required'] = false;
1182 }); 1226 });
1183 1227
1184 element.value = ''; 1228 element.value = '';
1185 _.triggerEvent(element, 'change'); 1229 _.triggerEvent(element, 'change');
1186 expect(element).toEqualValid(); 1230 expect(element).toEqualValid();
1187 1231
1188 scope.$apply(() { 1232 scope.apply(() {
1189 scope.required = true; 1233 scope.context['required'] = true;
1190 }); 1234 });
1191 expect(element).toEqualInvalid(); 1235 expect(element).toEqualInvalid();
1192 1236
1193 scope.$apply(() { 1237 scope.apply(() {
1194 scope.value = scope.values[0]; 1238 scope.context['value'] = scope.context['values'][0];
1195 }); 1239 });
1196 expect(element).toEqualValid(); 1240 expect(element).toEqualValid();
1197 1241
1198 element.value = ''; 1242 element.value = '';
1199 _.triggerEvent(element, 'change'); 1243 _.triggerEvent(element, 'change');
1200 expect(element).toEqualInvalid(); 1244 expect(element).toEqualInvalid();
1201 1245
1202 scope.$apply(() { 1246 scope.apply(() {
1203 scope.required = false; 1247 scope.context['required'] = false;
1204 }); 1248 });
1205 expect(element).toEqualValid(); 1249 expect(element).toEqualValid();
1206 }); 1250 });
1207 }); 1251 });
1208 }); 1252 });
1209 1253
1210 1254
1211 describe('option', () { 1255 describe('option', () {
1212 1256
1213 it('should populate value attribute on OPTION', () { 1257 it('should populate value attribute on OPTION', () {
1214 compile('<select ng-model="x"><option selected>abc</option></select>') ; 1258 compile('<select ng-model="x"><option selected>abc</option></select>') ;
1215 expect(element).toEqualSelect([['?'], 'abc']); 1259 expect(element).toEqualSelect([['?'], 'abc']);
1216 }); 1260 });
1217 1261
1218 it('should ignore value if already exists', () { 1262 it('should ignore value if already exists', () {
1219 compile('<select ng-model="x"><option value="abc">xyz</option></select >'); 1263 compile('<select ng-model="x"><option value="abc">xyz</option></select >');
1220 expect(element).toEqualSelect([['?'], 'abc']); 1264 expect(element).toEqualSelect([['?'], 'abc']);
1221 }); 1265 });
1222 1266
1223 it('should set value even if self closing HTML', () { 1267 it('should set value even if self closing HTML', () {
1224 scope.x = 'hello'; 1268 scope.context['x'] = 'hello';
1225 compile('<select ng-model="x"><option>hello</select>'); 1269 compile('<select ng-model="x"><option>hello</select>');
1226 expect(element).toEqualSelect([['hello']]); 1270 expect(element).toEqualSelect([['hello']]);
1227 }); 1271 });
1228 1272
1229 it('should not blow up when option directive is found inside of a datali st', 1273 it('should not blow up when option directive is found inside of a datali st',
1230 () { 1274 () {
1231 _.compile('<div>' + 1275 _.compile('<div>' +
1232 '<datalist><option>some val</option></datalist>' + 1276 '<datalist><option>some val</option></datalist>' +
1233 '<span>{{foo}}</span>' + 1277 '<span>{{foo}}</span>' +
1234 '</div>'); 1278 '</div>');
1235 1279
1236 _.rootScope.foo = 'success'; 1280 _.rootScope.context['foo'] = 'success';
1237 _.rootScope.$digest(); 1281 _.rootScope.apply();
1238 expect(_.rootElement.querySelector('span').text).toEqual('success'); 1282 expect(_.rootElement.querySelector('span').text).toEqual('success');
1239 }); 1283 });
1240 }); 1284 });
1241 }); 1285 });
1242 }); 1286 });
1243 } 1287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698