Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit ee52379

Browse files
author
Brett Knighton
committed
Karma tests for firstItemActive
1 parent 86ca206 commit ee52379

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

test/select.spec.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,12 +1233,15 @@ describe('ui-select tests', function() {
12331233
if (attrs.closeOnSelect !== undefined) { attrsHtml += ' close-on-select="' + attrs.closeOnSelect + '"'; }
12341234
if (attrs.tagging !== undefined) { attrsHtml += ' tagging="' + attrs.tagging + '"'; }
12351235
if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; }
1236+
if (attrs.firstItemActive === undefined) { attrs.firstItemActive = true; }
1237+
} else {
1238+
attrs = { firstItemActive: true };
12361239
}
12371240

12381241
return compileTemplate(
12391242
'<ui-select multiple ng-model="selection.selectedMultiple"' + attrsHtml + ' theme="bootstrap" style="width: 800px;"> \
12401243
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1241-
<ui-select-choices repeat="person in people | filter: $select.search" first-item-active="true"> \
1244+
<ui-select-choices repeat="person in people | filter: $select.search" first-item-active="' + attrs.firstItemActive + '"> \
12421245
<div ng-bind-html="person.name | highlight: $select.search"></div> \
12431246
<div ng-bind-html="person.email | highlight: $select.search"></div> \
12441247
</ui-select-choices> \
@@ -1505,12 +1508,31 @@ describe('ui-select tests', function() {
15051508
var searchInput = el.find('.ui-select-search');
15061509

15071510
triggerKeydown(searchInput, Key.Down); //Open dropdown
1508-
el.scope().$select.activeIndex = 0
1511+
el.scope().$select.activeIndex = 0;
15091512

1510-
triggerKeydown(searchInput, Key.Down)
1511-
triggerKeydown(searchInput, Key.Enter)
1513+
triggerKeydown(searchInput, Key.Down);
1514+
triggerKeydown(searchInput, Key.Enter);
15121515
expect(scope.selection.selectedMultiple.length).toEqual(2);
1516+
});
1517+
1518+
it('should close choices on ENTER when firstItemActive set to false', function() {
1519+
1520+
scope.selection.selectedMultiple = [scope.people[5]]; //Samantha
1521+
var el = createUiSelectMultiple({firstItemActive: false});
1522+
var searchInput = el.find('.ui-select-search');
1523+
1524+
triggerKeydown(searchInput, Key.Enter);
1525+
expect(el.scope().$select.open).toEqual(false);
1526+
});
1527+
1528+
it('should close choices on TAB when firstItemActive set to false', function() {
1529+
1530+
scope.selection.selectedMultiple = [scope.people[5]]; //Samantha
1531+
var el = createUiSelectMultiple({firstItemActive: false});
1532+
var searchInput = el.find('.ui-select-search');
15131533

1534+
triggerKeydown(searchInput, Key.Tab);
1535+
expect(el.scope().$select.open).toEqual(false);
15141536
});
15151537

15161538
it('should increase $select.activeIndex when pressing DOWN key from dropdown', function() {

0 commit comments

Comments
 (0)