@@ -8,7 +8,7 @@ describe('ui-select tests', function() {
8
8
$rootScope = _$rootScope_ ;
9
9
scope = $rootScope . $new ( ) ;
10
10
$compile = _$compile_ ;
11
- scope . selection = { }
11
+ scope . selection = { }
12
12
scope . getGroupLabel = function ( person ) {
13
13
return person . age % 2 ? 'even' : 'odd' ;
14
14
} ;
@@ -23,6 +23,18 @@ describe('ui-select tests', function() {
23
23
{ name :
'Nicole' , email :
'[email protected] ' , group :
'bar' , age :
43 } ,
24
24
{ name :
'Natasha' , email :
'[email protected] ' , group :
'Baz' , age :
54 }
25
25
] ;
26
+
27
+ scope . someObject = { } ;
28
+ scope . someObject . people = [
29
+ { name :
'Adam' , email :
'[email protected] ' , group :
'Foo' , age :
12 } ,
30
+ { name :
'Amalie' , email :
'[email protected] ' , group :
'Foo' , age :
12 } ,
31
+ { name :
'Estefanía' , email :
'estefaní[email protected] ' , group :
'Foo' , age :
21 } ,
32
+ { name :
'Adrian' , email :
'[email protected] ' , group :
'Foo' , age :
21 } ,
33
+ { name :
'Wladimir' , email :
'[email protected] ' , group :
'Foo' , age :
30 } ,
34
+ { name :
'Samantha' , email :
'[email protected] ' , group :
'bar' , age :
30 } ,
35
+ { name :
'Nicole' , email :
'[email protected] ' , group :
'bar' , age :
43 } ,
36
+ { name :
'Natasha' , email :
'[email protected] ' , group :
'Baz' , age :
54 }
37
+ ] ;
26
38
} ) ) ;
27
39
28
40
@@ -305,7 +317,7 @@ describe('ui-select tests', function() {
305
317
) ;
306
318
} ) . toThrow ( new Error ( '[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.' ) ) ;
307
319
} ) ;
308
-
320
+
309
321
it ( 'should format the model correctly using alias' , function ( ) {
310
322
var el = compileTemplate (
311
323
'<ui-select ng-model="selection.selected"> \
@@ -317,7 +329,7 @@ describe('ui-select tests', function() {
317
329
</ui-select>'
318
330
) ;
319
331
clickItem ( el , 'Samantha' ) ;
320
- expect ( scope . selection . selected ) . toBe ( scope . people [ 5 ] ) ;
332
+ expect ( scope . selection . selected ) . toBe ( scope . people [ 5 ] ) ;
321
333
} ) ;
322
334
323
335
it ( 'should parse the model correctly using alias' , function ( ) {
@@ -346,7 +358,7 @@ describe('ui-select tests', function() {
346
358
</ui-select>'
347
359
) ;
348
360
clickItem ( el , 'Samantha' ) ;
349
- expect ( scope . selection . selected ) . toBe ( 'Samantha' ) ;
361
+ expect ( scope . selection . selected ) . toBe ( 'Samantha' ) ;
350
362
} ) ;
351
363
352
364
it ( 'should parse the model correctly using property of alias' , function ( ) {
@@ -364,6 +376,7 @@ describe('ui-select tests', function() {
364
376
expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
365
377
} ) ;
366
378
379
+ //TODO Is this really something we should expect?
367
380
it ( 'should parse the model correctly using property of alias but passed whole object' , function ( ) {
368
381
var el = compileTemplate (
369
382
'<ui-select ng-model="selection.selected"> \
@@ -382,7 +395,7 @@ describe('ui-select tests', function() {
382
395
it ( 'should format the model correctly without alias' , function ( ) {
383
396
var el = createUiSelect ( ) ;
384
397
clickItem ( el , 'Samantha' ) ;
385
- expect ( scope . selection . selected ) . toBe ( scope . people [ 5 ] ) ;
398
+ expect ( scope . selection . selected ) . toBe ( scope . people [ 5 ] ) ;
386
399
} ) ;
387
400
388
401
it ( 'should parse the model correctly without alias' , function ( ) {
@@ -391,4 +404,34 @@ describe('ui-select tests', function() {
391
404
scope . $digest ( ) ;
392
405
expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
393
406
} ) ;
407
+
408
+ it ( 'should display choices correctly with child array' , function ( ) {
409
+ var el = compileTemplate (
410
+ '<ui-select ng-model="selection.selected"> \
411
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
412
+ <ui-select-choices repeat="person in someObject.people | filter: $select.search"> \
413
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
414
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
415
+ </ui-select-choices> \
416
+ </ui-select>'
417
+ ) ;
418
+ scope . selection . selected = scope . people [ 5 ] ;
419
+ scope . $digest ( ) ;
420
+ expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
421
+ } ) ;
422
+
423
+ it ( 'should format the model correctly using property of alias and when using child array for choices' , function ( ) {
424
+ var el = compileTemplate (
425
+ '<ui-select ng-model="selection.selected"> \
426
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
427
+ <ui-select-choices repeat="person.name as person in someObject.people | filter: $select.search"> \
428
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
429
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
430
+ </ui-select-choices> \
431
+ </ui-select>'
432
+ ) ;
433
+ clickItem ( el , 'Samantha' ) ;
434
+ expect ( scope . selection . selected ) . toBe ( 'Samantha' ) ;
435
+ } ) ;
436
+
394
437
} ) ;
0 commit comments