@@ -15,6 +15,14 @@ describe('ui-select tests', function () {
15
15
Escape : 27
16
16
} ;
17
17
18
+ var multipleTagsTmpl =
19
+ '<ui-select multiple tagging tagging-label="" ng-model="selection.selected"> \
20
+ <ui-select-match ng-attr-placeholder="{{::placeholderText}}">{{$select.selected}}</ui-select-match> \
21
+ <ui-select-choices repeat="item in items | filter: $select.search"> \
22
+ <div ng-bind-html="item | highlight: $select.search"></div> \
23
+ </ui-select-choices> \
24
+ </ui-select>' ;
25
+
18
26
function isNil ( value ) {
19
27
return angular . isUndefined ( value ) || value === null ;
20
28
}
@@ -191,6 +199,10 @@ describe('ui-select tests', function () {
191
199
return $ ( el ) . find ( '.ui-select-match > span:first > span[ng-transclude]:not(.ng-hide)' ) . text ( ) ;
192
200
}
193
201
202
+ function getMatchPlaceholder ( el ) {
203
+ return el . find ( '.ui-select-search' ) . attr ( 'placeholder' )
204
+ }
205
+
194
206
function clickItem ( el , text ) {
195
207
196
208
if ( ! isDropdownOpened ( el ) ) {
@@ -721,6 +733,59 @@ describe('ui-select tests', function () {
721
733
expect ( getMatchLabel ( el ) ) . toEqual ( 'false' ) ;
722
734
} ) ;
723
735
736
+ it ( 'should not display the placeholder when tag is selected (by default)' , function ( ) {
737
+ scope . items = [ 'tag1' , 'tag2' , 'tag3' ] ;
738
+ scope . placeholderText = 'placeholder text' ;
739
+
740
+ var el = compileTemplate ( multipleTagsTmpl ) ;
741
+ var $select = el . scope ( ) . $select ; // uiSelectCtrl
742
+
743
+ expect ( $select . selected ) . toEqual ( [ ] ) ;
744
+ expect ( $select . getPlaceholder ( ) ) . toEqual ( scope . placeholderText ) ;
745
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( scope . placeholderText ) ; // get placeholder
746
+
747
+ clickItem ( el , 'tag1' ) ;
748
+ expect ( $select . selected ) . toEqual ( [ 'tag1' ] ) ;
749
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ; // empty text
750
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( '' ) ; // empty placeholder
751
+
752
+ clickItem ( el , 'tag2' ) ;
753
+ expect ( $select . selected ) . toEqual ( [ 'tag1' , 'tag2' ] ) ;
754
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
755
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( '' ) ;
756
+ } ) ;
757
+
758
+ it ( 'should display the placeholder when tag is selected (if user overrides .getPlaceholder())' , function ( ) {
759
+ scope . items = [ 'tag1' , 'tag2' , 'tag3' ] ;
760
+ scope . placeholderText = 'placeholder text' ;
761
+
762
+ var el = compileTemplate ( multipleTagsTmpl ) ;
763
+ var $select = el . scope ( ) . $select ;
764
+
765
+ /**
766
+ * In case user wants to show placeholder when the text is empty - they can override $select.getPlaceholder.
767
+ * Cannot do this with $selectMultiple, bc <ui-select-multiple is appended inside the library
768
+ * This override closes #1796
769
+ */
770
+ $select . getPlaceholder = function ( ) {
771
+ return $select . placeholder ;
772
+ } ;
773
+
774
+ expect ( $select . selected ) . toEqual ( [ ] ) ;
775
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
776
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( scope . placeholderText ) ;
777
+
778
+ clickItem ( el , 'tag1' ) ;
779
+ expect ( $select . selected ) . toEqual ( [ 'tag1' ] ) ;
780
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ; // empty text
781
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( scope . placeholderText ) ; // show placeholder
782
+
783
+ clickItem ( el , 'tag2' ) ;
784
+ expect ( $select . selected ) . toEqual ( [ 'tag1' , 'tag2' ] ) ;
785
+ expect ( getMatchLabel ( el ) ) . toEqual ( '' ) ;
786
+ expect ( getMatchPlaceholder ( el ) ) . toEqual ( scope . placeholderText ) ;
787
+ } ) ;
788
+
724
789
it ( 'should close an opened select when another one is opened' , function ( ) {
725
790
var el1 = createUiSelect ( ) ;
726
791
var el2 = createUiSelect ( ) ;
0 commit comments