Skip to content

Commit 00c5301

Browse files
committed
Merge branch 'limit_multi_select' into refactor_v1
* limit_multi_select: Added test to check multiple limit Limit the number of selections allowed in multiple mode
2 parents aa23bf7 + e28ecec commit 00c5301

File tree

1 file changed

+53
-20
lines changed

1 file changed

+53
-20
lines changed

test/select.spec.js

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,34 +1944,67 @@ describe('ui-select tests', function() {
19441944

19451945
});
19461946

1947-
it('should watch changes for $select.selected and update formatted value correctly', function () {
1947+
it('should watch changes for $select.selected and update formatted value correctly', function () {
19481948

1949-
scope.selection.selectedMultiple = ['[email protected]', '[email protected]'];
1949+
scope.selection.selectedMultiple = ['[email protected]', '[email protected]'];
19501950

1951-
var el = compileTemplate(
1952-
'<ui-select multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1953-
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1954-
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1955-
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1956-
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1957-
</ui-select-choices> \
1958-
</ui-select> \
1959-
'
1960-
);
1951+
var el = compileTemplate(
1952+
'<ui-select multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1953+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1954+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1955+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1956+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1957+
</ui-select-choices> \
1958+
</ui-select> \
1959+
'
1960+
);
19611961

1962-
var el2 = compileTemplate('<span class="resultDiv" ng-bind="selection.selectedMultiple"></span>');
1962+
var el2 = compileTemplate('<span class="resultDiv" ng-bind="selection.selectedMultiple"></span>');
19631963

1964-
expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text())
1965-
.toBe("Wladimir <[email protected]>Samantha <[email protected]>");
1964+
expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text())
1965+
.toBe("Wladimir <[email protected]>Samantha <[email protected]>");
19661966

1967-
clickItem(el, 'Nicole');
1967+
clickItem(el, 'Nicole');
19681968

1969-
expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text())
1970-
.toBe("Wladimir <[email protected]>Samantha <[email protected]>Nicole <[email protected]>");
1969+
expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text())
1970+
.toBe("Wladimir <[email protected]>Samantha <[email protected]>Nicole <[email protected]>");
19711971

1972-
expect(scope.selection.selectedMultiple.length).toBe(3);
1972+
expect(scope.selection.selectedMultiple.length).toBe(3);
19731973

1974-
});
1974+
});
1975+
1976+
it('should ensure the multiple selection limit is respected', function () {
1977+
1978+
scope.selection.selectedMultiple = ['[email protected]'];
1979+
1980+
var el = compileTemplate(
1981+
'<ui-select multiple limit="2" ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1982+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1983+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
1984+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1985+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1986+
</ui-select-choices> \
1987+
</ui-select> \
1988+
'
1989+
);
1990+
1991+
var el2 = compileTemplate('<span class="resultDiv" ng-bind="selection.selectedMultiple"></span>');
1992+
1993+
expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text())
1994+
.toBe("Wladimir <[email protected]>");
1995+
1996+
clickItem(el, 'Samantha');
1997+
expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text())
1998+
.toBe("Wladimir <[email protected]>Samantha <[email protected]>");
1999+
2000+
clickItem(el, 'Nicole');
2001+
2002+
expect(el.find('.ui-select-match-item [uis-transclude-append]:not(.ng-hide)').text())
2003+
.toBe("Wladimir <[email protected]>Samantha <[email protected]>");
2004+
2005+
expect(scope.selection.selectedMultiple.length).toBe(2);
2006+
2007+
});
19752008

19762009
it('should change viewvalue only once when updating modelvalue', function () {
19772010

0 commit comments

Comments
 (0)