@@ -8,7 +8,7 @@ describe('ui-select tests', function() {
8
8
$rootScope = _$rootScope_ ;
9
9
scope = $rootScope . $new ( ) ;
10
10
$compile = _$compile_ ;
11
-
11
+ scope . selection = { }
12
12
scope . getGroupLabel = function ( person ) {
13
13
return person . age % 2 ? 'even' : 'odd' ;
14
14
} ;
@@ -42,7 +42,7 @@ describe('ui-select tests', function() {
42
42
}
43
43
44
44
return compileTemplate (
45
- '<ui-select ng-model="selection"' + attrsHtml + '> \
45
+ '<ui-select ng-model="selection.selected "' + attrsHtml + '> \
46
46
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
47
47
<ui-select-choices repeat="person in people | filter: $select.search"> \
48
48
<div ng-bind-html="person.name | highlight: $select.search"></div> \
@@ -102,7 +102,7 @@ describe('ui-select tests', function() {
102
102
} ) ;
103
103
104
104
it ( 'should correctly render initial state' , function ( ) {
105
- scope . selection = scope . people [ 0 ] ;
105
+ scope . selection . selected = scope . people [ 0 ] ;
106
106
107
107
var el = createUiSelect ( ) ;
108
108
@@ -178,7 +178,7 @@ describe('ui-select tests', function() {
178
178
scope . items = [ 'false' ] ;
179
179
180
180
var el = compileTemplate (
181
- '<ui-select ng-model="selection"> \
181
+ '<ui-select ng-model="selection.selected "> \
182
182
<ui-select-match>{{$select.selected}}</ui-select-match> \
183
183
<ui-select-choices repeat="item in items | filter: $select.search"> \
184
184
<div ng-bind-html="item | highlight: $select.search"></div> \
@@ -199,7 +199,7 @@ describe('ui-select tests', function() {
199
199
}
200
200
function createUiSelect ( ) {
201
201
return compileTemplate (
202
- '<ui-select ng-model="selection"> \
202
+ '<ui-select ng-model="selection.selected "> \
203
203
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
204
204
<ui-select-choices group-by="\'group\'" repeat="person in people | filter: $select.search"> \
205
205
<div ng-bind-html="person.name | highlight: $select.search"></div> \
@@ -249,7 +249,7 @@ describe('ui-select tests', function() {
249
249
describe ( 'choices group by function' , function ( ) {
250
250
function createUiSelect ( ) {
251
251
return compileTemplate (
252
- '<ui-select ng-model="selection"> \
252
+ '<ui-select ng-model="selection.selected "> \
253
253
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
254
254
<ui-select-choices group-by="getGroupLabel" repeat="person in people | filter: $select.search"> \
255
255
<div ng-bind-html="person.name | highlight: $select.search"></div> \
@@ -268,7 +268,7 @@ describe('ui-select tests', function() {
268
268
it ( 'should throw when no ui-select-choices found' , function ( ) {
269
269
expect ( function ( ) {
270
270
compileTemplate (
271
- '<ui-select ng-model="selection"> \
271
+ '<ui-select ng-model="selection.selected "> \
272
272
<ui-select-match></ui-select-match> \
273
273
</ui-select>'
274
274
) ;
@@ -278,7 +278,7 @@ describe('ui-select tests', function() {
278
278
it ( 'should throw when no repeat attribute is provided to ui-select-choices' , function ( ) {
279
279
expect ( function ( ) {
280
280
compileTemplate (
281
- '<ui-select ng-model="selection"> \
281
+ '<ui-select ng-model="selection.selected "> \
282
282
<ui-select-choices></ui-select-choices> \
283
283
</ui-select>'
284
284
) ;
@@ -288,9 +288,96 @@ describe('ui-select tests', function() {
288
288
it ( 'should throw when no ui-select-match found' , function ( ) {
289
289
expect ( function ( ) {
290
290
compileTemplate (
291
- '<ui-select ng-model="selection"> \
291
+ '<ui-select ng-model="selection.selected "> \
292
292
<ui-select-choices repeat="item in items"></ui-select-choices> \
293
293
</ui-select>'
294
294
) ;
295
295
} ) . toThrow ( new Error ( '[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.' ) ) ;
296
- } ) ; } ) ;
296
+ } ) ;
297
+
298
+ it ( 'should format the model correctly using alias' , function ( ) {
299
+ var el = compileTemplate (
300
+ '<ui-select ng-model="selection.selected"> \
301
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
302
+ <ui-select-choices repeat="person as person in people | filter: $select.search"> \
303
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
304
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
305
+ </ui-select-choices> \
306
+ </ui-select>'
307
+ ) ;
308
+ clickItem ( el , 'Samantha' ) ;
309
+ expect ( scope . selection . selected ) . toBe ( scope . people [ 5 ] ) ;
310
+ } ) ;
311
+
312
+ it ( 'should parse the model correctly using alias' , function ( ) {
313
+ var el = compileTemplate (
314
+ '<ui-select ng-model="selection.selected"> \
315
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
316
+ <ui-select-choices repeat="person as person in people | filter: $select.search"> \
317
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
318
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
319
+ </ui-select-choices> \
320
+ </ui-select>'
321
+ ) ;
322
+ scope . selection . selected = scope . people [ 5 ] ;
323
+ scope . $digest ( ) ;
324
+ expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
325
+ } ) ;
326
+
327
+ it ( 'should format the model correctly using property of alias' , function ( ) {
328
+ var el = compileTemplate (
329
+ '<ui-select ng-model="selection.selected"> \
330
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
331
+ <ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
332
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
333
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
334
+ </ui-select-choices> \
335
+ </ui-select>'
336
+ ) ;
337
+ clickItem ( el , 'Samantha' ) ;
338
+ expect ( scope . selection . selected ) . toBe ( 'Samantha' ) ;
339
+ } ) ;
340
+
341
+ it ( 'should parse the model correctly using property of alias' , function ( ) {
342
+ var el = compileTemplate (
343
+ '<ui-select ng-model="selection.selected"> \
344
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
345
+ <ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
346
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
347
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
348
+ </ui-select-choices> \
349
+ </ui-select>'
350
+ ) ;
351
+ scope . selection . selected = 'Samantha' ;
352
+ scope . $digest ( ) ;
353
+ expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
354
+ } ) ;
355
+
356
+ it ( 'should parse the model correctly using property of alias but passed whole object' , function ( ) {
357
+ var el = compileTemplate (
358
+ '<ui-select ng-model="selection.selected"> \
359
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
360
+ <ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
361
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
362
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
363
+ </ui-select-choices> \
364
+ </ui-select>'
365
+ ) ;
366
+ scope . selection . selected = scope . people [ 5 ] ;
367
+ scope . $digest ( ) ;
368
+ expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
369
+ } ) ;
370
+
371
+ it ( 'should format the model correctly without alias' , function ( ) {
372
+ var el = createUiSelect ( ) ;
373
+ clickItem ( el , 'Samantha' ) ;
374
+ expect ( scope . selection . selected ) . toBe ( scope . people [ 5 ] ) ;
375
+ } ) ;
376
+
377
+ it ( 'should parse the model correctly without alias' , function ( ) {
378
+ var el = createUiSelect ( ) ;
379
+ scope . selection . selected = scope . people [ 5 ] ;
380
+ scope . $digest ( ) ;
381
+ expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
382
+ } ) ;
383
+ } ) ;
0 commit comments