1
1
'use strict' ;
2
2
3
3
describe ( 'ui-select tests' , function ( ) {
4
- var scope , $rootScope , $compile , $timeout ;
4
+ var scope , $rootScope , $compile , $timeout , $injector ;
5
5
6
6
var Key = {
7
7
Enter : 13 ,
@@ -16,11 +16,12 @@ describe('ui-select tests', function() {
16
16
} ;
17
17
18
18
beforeEach ( module ( 'ngSanitize' , 'ui.select' ) ) ;
19
- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$timeout_ ) {
19
+ beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$timeout_ , _$injector_ ) {
20
20
$rootScope = _$rootScope_ ;
21
21
scope = $rootScope . $new ( ) ;
22
22
$compile = _$compile_ ;
23
23
$timeout = _$timeout_ ;
24
+ $injector = _$injector_ ;
24
25
scope . selection = { } ;
25
26
26
27
scope . getGroupLabel = function ( person ) {
@@ -144,6 +145,7 @@ describe('ui-select tests', function() {
144
145
var choicesContainerEl = $ ( el ) . find ( '.ui-select-choices' ) ;
145
146
expect ( choicesContainerEl . length ) . toEqual ( 1 ) ;
146
147
148
+ openDropdown ( el ) ;
147
149
var choicesEls = $ ( el ) . find ( '.ui-select-choices-row' ) ;
148
150
expect ( choicesEls . length ) . toEqual ( 8 ) ;
149
151
} ) ;
@@ -254,7 +256,7 @@ describe('ui-select tests', function() {
254
256
expect ( isDropdownOpened ( el2 ) ) . toEqual ( true ) ;
255
257
256
258
var el3 = createUiSelect ( ) ;
257
- expect ( el3 . scope ( ) . $select . disabled ) . toEqual ( false ) ;
259
+ expect ( el3 . scope ( ) . $select . disabled ) . toEqual ( false || undefined ) ;
258
260
clickMatch ( el3 ) ;
259
261
expect ( isDropdownOpened ( el3 ) ) . toEqual ( true ) ;
260
262
} ) ;
@@ -401,12 +403,14 @@ describe('ui-select tests', function() {
401
403
} ) ;
402
404
403
405
it ( 'should set a disabled class on the option' , function ( ) {
404
- var option = $ ( this . el ) . find ( '.ui-select-choices-row div:contains("Wladimir")' ) ;
405
- var container = option . closest ( '.ui-select-choices-row' ) ;
406
406
407
407
openDropdown ( this . el ) ;
408
408
409
+ var option = $ ( this . el ) . find ( '.ui-select-choices-row div:contains("Wladimir")' ) ;
410
+ var container = option . closest ( '.ui-select-choices-row' ) ;
411
+
409
412
expect ( container . hasClass ( 'disabled' ) ) . toBeTruthy ( ) ;
413
+
410
414
} ) ;
411
415
} ) ;
412
416
@@ -432,11 +436,11 @@ describe('ui-select tests', function() {
432
436
} ) ;
433
437
434
438
it ( 'should set a disabled class on the option' , function ( ) {
439
+ openDropdown ( this . el ) ;
440
+
435
441
var option = $ ( this . el ) . find ( '.ui-select-choices-row div:contains("Wladimir")' ) ;
436
442
var container = option . closest ( '.ui-select-choices-row' ) ;
437
443
438
- openDropdown ( this . el ) ;
439
-
440
444
expect ( container . hasClass ( 'disabled' ) ) . toBeTruthy ( ) ;
441
445
} ) ;
442
446
} ) ;
@@ -463,11 +467,11 @@ describe('ui-select tests', function() {
463
467
} ) ;
464
468
465
469
it ( 'should set a disabled class on the option' , function ( ) {
470
+ openDropdown ( this . el ) ;
471
+
466
472
var option = $ ( this . el ) . find ( '.ui-select-choices-row div:contains("Wladimir")' ) ;
467
473
var container = option . closest ( '.ui-select-choices-row' ) ;
468
474
469
- openDropdown ( this . el ) ;
470
-
471
475
expect ( container . hasClass ( 'disabled' ) ) . toBeTruthy ( ) ;
472
476
} ) ;
473
477
} ) ;
@@ -519,9 +523,8 @@ describe('ui-select tests', function() {
519
523
var el = createUiSelect ( ) ;
520
524
el . scope ( ) . $select . search = 't' ;
521
525
scope . $digest ( ) ;
522
- var choices = el . find ( '.ui-select-choices-row' ) ;
523
-
524
526
openDropdown ( el ) ;
527
+ var choices = el . find ( '.ui-select-choices-row' ) ;
525
528
526
529
expect ( choices . eq ( 0 ) ) . toHaveClass ( 'active' ) ;
527
530
expect ( getGroupLabel ( choices . eq ( 0 ) ) . text ( ) ) . toBe ( 'Foo' ) ;
@@ -759,6 +762,35 @@ describe('ui-select tests', function() {
759
762
760
763
} ) ;
761
764
765
+ it ( 'should invoke hover callback' , function ( ) {
766
+
767
+ var highlighted ;
768
+ scope . onHighlightFn = function ( $item ) {
769
+ highlighted = $item ;
770
+ } ;
771
+
772
+ var el = compileTemplate (
773
+ '<ui-select on-select="onSelectFn($item, $model)" ng-model="selection.selected"> \
774
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
775
+ <ui-select-choices on-highlight="onHighlightFn(person)" repeat="person.name as person in people | filter: $select.search"> \
776
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
777
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
778
+ </ui-select-choices> \
779
+ </ui-select>'
780
+ ) ;
781
+
782
+ expect ( highlighted ) . toBeFalsy ( ) ;
783
+
784
+ if ( ! isDropdownOpened ( el ) ) {
785
+ openDropdown ( el ) ;
786
+ }
787
+
788
+ $ ( el ) . find ( '.ui-select-choices-row div:contains("Samantha")' ) . trigger ( 'mouseover' ) ;
789
+ scope . $digest ( ) ;
790
+
791
+ expect ( highlighted ) . toBe ( scope . people [ 5 ] ) ;
792
+ } )
793
+
762
794
it ( 'should set $item & $model correctly when invoking callback on select and no single prop. binding' , function ( ) {
763
795
764
796
scope . onSelectFn = function ( $item , $model , $label ) {
@@ -878,6 +910,7 @@ describe('ui-select tests', function() {
878
910
</ui-select>'
879
911
) ;
880
912
913
+ openDropdown ( el ) ;
881
914
expect ( $ ( el ) . find ( '.only-once' ) . length ) . toEqual ( 1 ) ;
882
915
883
916
@@ -993,12 +1026,12 @@ describe('ui-select tests', function() {
993
1026
describe ( 'selectize theme' , function ( ) {
994
1027
995
1028
it ( 'should show search input when true' , function ( ) {
996
- setupSelectComponent ( ' true' , 'selectize' ) ;
1029
+ setupSelectComponent ( true , 'selectize' ) ;
997
1030
expect ( $ ( el ) . find ( '.ui-select-search' ) ) . not . toHaveClass ( 'ng-hide' ) ;
998
1031
} ) ;
999
1032
1000
1033
it ( 'should hide search input when false' , function ( ) {
1001
- setupSelectComponent ( ' false' , 'selectize' ) ;
1034
+ setupSelectComponent ( false , 'selectize' ) ;
1002
1035
expect ( $ ( el ) . find ( '.ui-select-search' ) ) . toHaveClass ( 'ng-hide' ) ;
1003
1036
} ) ;
1004
1037
@@ -1507,5 +1540,64 @@ describe('ui-select tests', function() {
1507
1540
} ) ;
1508
1541
} ) ;
1509
1542
1543
+ describe ( 'default configuration via uiSelectConfig' , function ( ) {
1544
+
1545
+ describe ( 'searchEnabled option' , function ( ) {
1546
+
1547
+ function setupWithoutAttr ( ) {
1548
+ return compileTemplate (
1549
+ '<ui-select ng-model="selection.selected"> \
1550
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1551
+ <ui-select-choices repeat="person in people | filter: $select.search"> \
1552
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
1553
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
1554
+ </ui-select-choices> \
1555
+ </ui-select>'
1556
+ ) ;
1557
+ }
1510
1558
1559
+ function setupWithAttr ( searchEnabled ) {
1560
+ return compileTemplate (
1561
+ '<ui-select ng-model="selection.selected" search-enabled="' + searchEnabled + '"> \
1562
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1563
+ <ui-select-choices repeat="person in people | filter: $select.search"> \
1564
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
1565
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
1566
+ </ui-select-choices> \
1567
+ </ui-select>'
1568
+ ) ;
1569
+ }
1570
+
1571
+ it ( 'should be true by default' , function ( ) {
1572
+ var el = setupWithoutAttr ( ) ;
1573
+ expect ( el . scope ( ) . $select . searchEnabled ) . toBe ( true ) ;
1574
+ } ) ;
1575
+
1576
+ it ( 'should disable search if default set to false' , function ( ) {
1577
+ var uiSelectConfig = $injector . get ( 'uiSelectConfig' ) ;
1578
+ uiSelectConfig . searchEnabled = false ;
1579
+
1580
+ var el = setupWithoutAttr ( ) ;
1581
+ expect ( el . scope ( ) . $select . searchEnabled ) . not . toBe ( true ) ;
1582
+ } ) ;
1583
+
1584
+ it ( 'should be overridden by inline option search-enabled=true' , function ( ) {
1585
+ var uiSelectConfig = $injector . get ( 'uiSelectConfig' ) ;
1586
+ uiSelectConfig . searchEnabled = false ;
1587
+
1588
+ var el = setupWithAttr ( true ) ;
1589
+ expect ( el . scope ( ) . $select . searchEnabled ) . toBe ( true ) ;
1590
+ } ) ;
1591
+
1592
+ it ( 'should be overridden by inline option search-enabled=false' , function ( ) {
1593
+ var uiSelectConfig = $injector . get ( 'uiSelectConfig' ) ;
1594
+ uiSelectConfig . searchEnabled = true ;
1595
+
1596
+ var el = setupWithAttr ( false ) ;
1597
+ expect ( el . scope ( ) . $select . searchEnabled ) . not . toBe ( true ) ;
1598
+ } ) ;
1599
+
1600
+ } ) ;
1601
+
1602
+ } ) ;
1511
1603
} ) ;
0 commit comments