@@ -407,31 +407,59 @@ describe('select', function() {
407
407
} ) ;
408
408
409
409
describe ( 'selectController.hasOption' , function ( ) {
410
- it ( 'should return true for options added via ngOptions' , function ( ) {
410
+ it ( 'should return false for options shifted via ngOptions' , function ( ) {
411
411
scope . robots = [
412
- { key : 1 , value : 'c3p0' } ,
413
- { key : 2 , value : 'r2d2' }
412
+ { value : 1 , label : 'c3p0' } ,
413
+ { value : 2 , label : 'r2d2' }
414
414
] ;
415
- scope . robot = 'r2d2' ;
416
415
417
416
compile ( '<select ng-model="robot" ' +
418
- 'ng-options="item.key as item.value for item in robots">' +
417
+ 'ng-options="item.value as item.label for item in robots">' +
419
418
'</select>' ) ;
420
419
421
420
var selectCtrl = element . data ( ) . $selectController ;
422
421
423
- expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
422
+ scope . $apply ( function ( ) {
423
+ scope . robots . shift ( ) ;
424
+ } ) ;
425
+
426
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( false ) ;
424
427
expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
428
+ } ) ;
429
+
430
+ it ( 'should return false for options popped via ngOptions' , function ( ) {
431
+ scope . robots = [
432
+ { value : 1 , label : 'c3p0' } ,
433
+ { value : 2 , label : 'r2d2' }
434
+ ] ;
435
+
436
+ compile ( '<select ng-model="robot" ' +
437
+ 'ng-options="item.value as item.label for item in robots">' +
438
+ '</select>' ) ;
439
+
440
+ var selectCtrl = element . data ( ) . $selectController ;
425
441
426
442
scope . $apply ( function ( ) {
427
443
scope . robots . pop ( ) ;
428
444
} ) ;
429
445
430
446
expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
431
447
expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( false ) ;
448
+ } ) ;
449
+
450
+ it ( 'should return true for options added via ngOptions' , function ( ) {
451
+ scope . robots = [
452
+ { value : 2 , label : 'r2d2' }
453
+ ] ;
454
+
455
+ compile ( '<select ng-model="robot" ' +
456
+ 'ng-options="item.value as item.label for item in robots">' +
457
+ '</select>' ) ;
458
+
459
+ var selectCtrl = element . data ( ) . $selectController ;
432
460
433
461
scope . $apply ( function ( ) {
434
- scope . robots . push ( { key : 2 , value : 'r2d2 ' } ) ;
462
+ scope . robots . unshift ( { value : 1 , label : 'c3p0 ' } ) ;
435
463
} ) ;
436
464
437
465
expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
@@ -516,31 +544,59 @@ describe('select', function() {
516
544
} ) ;
517
545
518
546
describe ( 'selectController.hasOption' , function ( ) {
519
- it ( 'should return true for options added via ngOptions' , function ( ) {
547
+ it ( 'should return false for options shifted via ngOptions' , function ( ) {
520
548
scope . robots = [
521
- { key : 1 , value : 'c3p0' } ,
522
- { key : 2 , value : 'r2d2' }
549
+ { value : 1 , label : 'c3p0' } ,
550
+ { value : 2 , label : 'r2d2' }
523
551
] ;
524
- scope . robot = 'r2d2' ;
525
552
526
553
compile ( '<select ng-model="robot" multiple ' +
527
- 'ng-options="item.key as item.value for item in robots">' +
554
+ 'ng-options="item.value as item.label for item in robots">' +
528
555
'</select>' ) ;
529
556
530
557
var selectCtrl = element . data ( ) . $selectController ;
531
558
532
- expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
559
+ scope . $apply ( function ( ) {
560
+ scope . robots . shift ( ) ;
561
+ } ) ;
562
+
563
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( false ) ;
533
564
expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
565
+ } ) ;
566
+
567
+ it ( 'should return false for options popped via ngOptions' , function ( ) {
568
+ scope . robots = [
569
+ { value : 1 , label : 'c3p0' } ,
570
+ { value : 2 , label : 'r2d2' }
571
+ ] ;
572
+
573
+ compile ( '<select ng-model="robot" multiple ' +
574
+ 'ng-options="item.value as item.label for item in robots">' +
575
+ '</select>' ) ;
576
+
577
+ var selectCtrl = element . data ( ) . $selectController ;
534
578
535
579
scope . $apply ( function ( ) {
536
580
scope . robots . pop ( ) ;
537
581
} ) ;
538
582
539
583
expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
540
584
expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( false ) ;
585
+ } ) ;
586
+
587
+ it ( 'should return true for options added via ngOptions' , function ( ) {
588
+ scope . robots = [
589
+ { value : 2 , label : 'r2d2' }
590
+ ] ;
591
+
592
+ compile ( '<select ng-model="robot" multiple ' +
593
+ 'ng-options="item.value as item.label for item in robots">' +
594
+ '</select>' ) ;
595
+
596
+ var selectCtrl = element . data ( ) . $selectController ;
541
597
542
598
scope . $apply ( function ( ) {
543
- scope . robots . push ( { key : 2 , value : 'r2d2 ' } ) ;
599
+ scope . robots . unshift ( { value : 1 , label : 'c3p0 ' } ) ;
544
600
} ) ;
545
601
546
602
expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
0 commit comments