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,13 +16,14 @@ 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 ) {
27
28
return person . age % 2 ? 'even' : 'odd' ;
28
29
} ;
@@ -208,7 +209,7 @@ describe('ui-select tests', function() {
208
209
var el = createUiSelect ( { theme : 'select2' } ) ;
209
210
var searchInput = el . find ( '.ui-select-search' ) ;
210
211
var $select = el . scope ( ) . $select ;
211
-
212
+
212
213
expect ( $select . open ) . toEqual ( false ) ;
213
214
214
215
el . find ( ".ui-select-toggle" ) . click ( ) ;
@@ -485,9 +486,9 @@ describe('ui-select tests', function() {
485
486
el . scope ( ) . $select . search = 't' ;
486
487
scope . $digest ( ) ;
487
488
var choices = el . find ( '.ui-select-choices-row' ) ;
488
-
489
+
489
490
openDropdown ( el ) ;
490
-
491
+
491
492
expect ( choices . eq ( 0 ) ) . toHaveClass ( 'active' ) ;
492
493
expect ( getGroupLabel ( choices . eq ( 0 ) ) . text ( ) ) . toBe ( 'Foo' ) ;
493
494
@@ -571,7 +572,7 @@ describe('ui-select tests', function() {
571
572
clickItem ( el , 'Samantha' ) ;
572
573
expect ( scope . selection . selected ) . toBe ( scope . people [ 5 ] ) ;
573
574
} ) ;
574
-
575
+
575
576
it ( 'should parse the model correctly using alias' , function ( ) {
576
577
var el = compileTemplate (
577
578
'<ui-select ng-model="selection.selected"> \
@@ -586,7 +587,7 @@ describe('ui-select tests', function() {
586
587
scope . $digest ( ) ;
587
588
expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
588
589
} ) ;
589
-
590
+
590
591
it ( 'should format the model correctly using property of alias' , function ( ) {
591
592
var el = compileTemplate (
592
593
'<ui-select ng-model="selection.selected"> \
@@ -600,7 +601,7 @@ describe('ui-select tests', function() {
600
601
clickItem ( el , 'Samantha' ) ;
601
602
expect ( scope . selection . selected ) . toBe ( 'Samantha' ) ;
602
603
} ) ;
603
-
604
+
604
605
it ( 'should parse the model correctly using property of alias' , function ( ) {
605
606
var el = compileTemplate (
606
607
'<ui-select ng-model="selection.selected"> \
@@ -615,7 +616,7 @@ describe('ui-select tests', function() {
615
616
scope . $digest ( ) ;
616
617
expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
617
618
} ) ;
618
-
619
+
619
620
it ( 'should parse the model correctly using property of alias with async choices data' , function ( ) {
620
621
var el = compileTemplate (
621
622
'<ui-select ng-model="selection.selected"> \
@@ -654,13 +655,13 @@ describe('ui-select tests', function() {
654
655
scope . $digest ( ) ;
655
656
expect ( getMatchLabel ( el ) ) . toEqual ( 'Samantha' ) ;
656
657
} ) ;
657
-
658
+
658
659
it ( 'should format the model correctly without alias' , function ( ) {
659
660
var el = createUiSelect ( ) ;
660
661
clickItem ( el , 'Samantha' ) ;
661
662
expect ( scope . selection . selected ) . toBe ( scope . people [ 5 ] ) ;
662
663
} ) ;
663
-
664
+
664
665
it ( 'should parse the model correctly without alias' , function ( ) {
665
666
var el = createUiSelect ( ) ;
666
667
scope . selection . selected = scope . people [ 5 ] ;
@@ -922,8 +923,8 @@ describe('ui-select tests', function() {
922
923
scope . fetchFromServer = function ( searching ) {
923
924
924
925
if ( searching == 's' )
925
- return scope . people
926
-
926
+ return scope . people
927
+
927
928
if ( searching == 'o' ) {
928
929
scope . people = [ ] ; //To simulate cases were previously selected item isnt in the list anymore
929
930
}
@@ -958,12 +959,12 @@ describe('ui-select tests', function() {
958
959
describe ( 'selectize theme' , function ( ) {
959
960
960
961
it ( 'should show search input when true' , function ( ) {
961
- setupSelectComponent ( ' true' , 'selectize' ) ;
962
+ setupSelectComponent ( true , 'selectize' ) ;
962
963
expect ( $ ( el ) . find ( '.ui-select-search' ) ) . not . toHaveClass ( 'ng-hide' ) ;
963
964
} ) ;
964
965
965
966
it ( 'should hide search input when false' , function ( ) {
966
- setupSelectComponent ( ' false' , 'selectize' ) ;
967
+ setupSelectComponent ( false , 'selectize' ) ;
967
968
expect ( $ ( el ) . find ( '.ui-select-search' ) ) . toHaveClass ( 'ng-hide' ) ;
968
969
} ) ;
969
970
@@ -1031,7 +1032,7 @@ describe('ui-select tests', function() {
1031
1032
} ) ;
1032
1033
1033
1034
it ( 'should set model as an empty array if ngModel isnt defined' , function ( ) {
1034
-
1035
+
1035
1036
// scope.selection.selectedMultiple = [];
1036
1037
var el = createUiSelectMultiple ( ) ;
1037
1038
@@ -1117,7 +1118,7 @@ describe('ui-select tests', function() {
1117
1118
triggerKeydown ( searchInput , Key . Left ) ;
1118
1119
triggerKeydown ( searchInput , Key . Backspace ) ;
1119
1120
expect ( el . scope ( ) . $select . selected ) . toEqual ( [ scope . people [ 4 ] , scope . people [ 6 ] ] ) ; //Wladimir & Nicole
1120
-
1121
+
1121
1122
expect ( el . scope ( ) . $select . activeMatchIndex ) . toBe ( 0 ) ;
1122
1123
1123
1124
} ) ;
@@ -1133,7 +1134,7 @@ describe('ui-select tests', function() {
1133
1134
triggerKeydown ( searchInput , Key . Left ) ;
1134
1135
triggerKeydown ( searchInput , Key . Delete ) ;
1135
1136
expect ( el . scope ( ) . $select . selected ) . toEqual ( [ scope . people [ 4 ] , scope . people [ 6 ] ] ) ; //Wladimir & Nicole
1136
-
1137
+
1137
1138
expect ( el . scope ( ) . $select . activeMatchIndex ) . toBe ( 1 ) ;
1138
1139
1139
1140
} ) ;
@@ -1348,7 +1349,7 @@ describe('ui-select tests', function() {
1348
1349
} ) ;
1349
1350
1350
1351
it ( 'should format view value correctly when using single property binding and refresh funcion' , function ( ) {
1351
-
1352
+
1352
1353
scope . selection . selectedMultiple = [ 'wladimir@email.com' , 'samantha@email.com' ] ;
1353
1354
1354
1355
var el = compileTemplate (
@@ -1367,8 +1368,8 @@ describe('ui-select tests', function() {
1367
1368
scope . fetchFromServer = function ( searching ) {
1368
1369
1369
1370
if ( searching == 'n' )
1370
- return scope . people
1371
-
1371
+ return scope . people
1372
+
1372
1373
if ( searching == 'o' ) {
1373
1374
scope . people = [ ] ; //To simulate cases were previously selected item isnt in the list anymore
1374
1375
}
@@ -1389,7 +1390,7 @@ describe('ui-select tests', function() {
1389
1390
} ) ;
1390
1391
1391
1392
it ( 'should watch changes for $select.selected and update formatted value correctly' , function ( ) {
1392
-
1393
+
1393
1394
scope . selection . selectedMultiple = [ 'wladimir@email.com' , 'samantha@email.com' ] ;
1394
1395
1395
1396
var el = compileTemplate (
@@ -1418,7 +1419,7 @@ describe('ui-select tests', function() {
1418
1419
} ) ;
1419
1420
1420
1421
it ( 'should change viewvalue only once when updating modelvalue' , function ( ) {
1421
-
1422
+
1422
1423
scope . selection . selectedMultiple = [ 'wladimir@email.com' , 'samantha@email.com' ] ;
1423
1424
1424
1425
var el = compileTemplate (
@@ -1445,7 +1446,7 @@ describe('ui-select tests', function() {
1445
1446
1446
1447
1447
1448
it ( 'should run $formatters when changing model directly' , function ( ) {
1448
-
1449
+
1449
1450
scope . selection . selectedMultiple = [ 'wladimir@email.com' , 'samantha@email.com' ] ;
1450
1451
1451
1452
var el = compileTemplate (
@@ -1472,5 +1473,64 @@ describe('ui-select tests', function() {
1472
1473
} ) ;
1473
1474
} ) ;
1474
1475
1476
+ describe ( 'default configuration via uiSelectConfig' , function ( ) {
1477
+
1478
+ describe ( 'searchEnabled option' , function ( ) {
1475
1479
1480
+ function setupWithoutAttr ( ) {
1481
+ return compileTemplate (
1482
+ '<ui-select ng-model="selection.selected"> \
1483
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1484
+ <ui-select-choices repeat="person in people | filter: $select.search"> \
1485
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
1486
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
1487
+ </ui-select-choices> \
1488
+ </ui-select>'
1489
+ ) ;
1490
+ }
1491
+
1492
+ function setupWithAttr ( searchEnabled ) {
1493
+ return compileTemplate (
1494
+ '<ui-select ng-model="selection.selected" search-enabled="' + searchEnabled + '"> \
1495
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1496
+ <ui-select-choices repeat="person in people | filter: $select.search"> \
1497
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
1498
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
1499
+ </ui-select-choices> \
1500
+ </ui-select>'
1501
+ ) ;
1502
+ }
1503
+
1504
+ it ( 'should be true by default' , function ( ) {
1505
+ var el = setupWithoutAttr ( ) ;
1506
+ expect ( el . scope ( ) . $select . searchEnabled ) . toBe ( true ) ;
1507
+ } ) ;
1508
+
1509
+ it ( 'should disable search if default set to false' , function ( ) {
1510
+ var uiSelectConfig = $injector . get ( 'uiSelectConfig' ) ;
1511
+ uiSelectConfig . searchEnabled = false ;
1512
+
1513
+ var el = setupWithoutAttr ( ) ;
1514
+ expect ( el . scope ( ) . $select . searchEnabled ) . not . toBe ( true ) ;
1515
+ } ) ;
1516
+
1517
+ it ( 'should be overridden by inline option search-enabled=true' , function ( ) {
1518
+ var uiSelectConfig = $injector . get ( 'uiSelectConfig' ) ;
1519
+ uiSelectConfig . searchEnabled = false ;
1520
+
1521
+ var el = setupWithAttr ( true ) ;
1522
+ expect ( el . scope ( ) . $select . searchEnabled ) . toBe ( true ) ;
1523
+ } ) ;
1524
+
1525
+ it ( 'should be overridden by inline option search-enabled=false' , function ( ) {
1526
+ var uiSelectConfig = $injector . get ( 'uiSelectConfig' ) ;
1527
+ uiSelectConfig . searchEnabled = true ;
1528
+
1529
+ var el = setupWithAttr ( false ) ;
1530
+ expect ( el . scope ( ) . $select . searchEnabled ) . not . toBe ( true ) ;
1531
+ } ) ;
1532
+
1533
+ } ) ;
1534
+
1535
+ } ) ;
1476
1536
} ) ;
0 commit comments