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

Commit 37f52f6

Browse files
committed
Add test
1 parent 4d70390 commit 37f52f6

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/select.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@
12421242
$select.disableChoiceExpression = attrs.uiDisableChoice;
12431243
$select.onHighlightCallback = attrs.onHighlight;
12441244

1245-
$select.refreshOnActive = attrs.refreshOnActive;
1245+
$select.refreshOnActive = scope.$eval(attrs.refreshOnActive);
12461246

12471247
if(groupByExp) {
12481248
var groups = element.querySelectorAll('.ui-select-choices-group');
@@ -1269,13 +1269,13 @@
12691269
scope.$watch('$select.search', function(newValue) {
12701270
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
12711271
$select.activeIndex = $select.tagging.isActivated ? -1 : 0;
1272-
if(angular.isUndefined($select.refreshOnActive) || ($select.refreshOnActive && $select.refreshIsActive)) {
1272+
if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) {
12731273
$select.refresh(attrs.refresh);
12741274
}
12751275
});
12761276

1277-
scope.$watch('$select.refreshIsActive', function(value){
1278-
if(angular.isUndefined(value)){
1277+
scope.$watch('$select.refreshIsActive', function(newValue, oldValue){
1278+
if(angular.isUndefined(oldValue) && newValue){
12791279
$select.refresh(attrs.refresh);
12801280
}
12811281
});

test/select.spec.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('ui-select tests', function() {
158158

159159
expect(getMatchLabel(el)).toEqual('Adam');
160160
});
161-
161+
162162
it('should correctly render initial state with track by feature', function() {
163163
var el = compileTemplate(
164164
'<ui-select ng-model="selection.selected"> \
@@ -1700,4 +1700,33 @@ describe('ui-select tests', function() {
17001700
}
17011701
});
17021702
});
1703+
1704+
describe('with refresh on active', function(){
1705+
it('should not refresh untill is activate', function(){
1706+
1707+
var el = compileTemplate(
1708+
'<ui-select ng-model="selection.selected"> \
1709+
<ui-select-match> \
1710+
</ui-select-match> \
1711+
<ui-select-choices repeat="person in people | filter: $select.search" \
1712+
refresh="fetchFromServer($select.search)" refresh-on-active="true" refresh-delay="0"> \
1713+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1714+
<div ng-if="person.name==\'Wladimir\'"> \
1715+
<span class="only-once">I should appear only once</span>\
1716+
</div> \
1717+
</ui-select-choices> \
1718+
</ui-select>'
1719+
);
1720+
1721+
scope.fetchFromServer = function(){};
1722+
spyOn(scope, 'fetchFromServer');
1723+
$timeout.flush();
1724+
expect(scope.fetchFromServer.calls.any()).toEqual(false);
1725+
1726+
el.scope().$select.activate();
1727+
$timeout.flush();
1728+
expect(scope.fetchFromServer.calls.any()).toEqual(true);
1729+
});
1730+
1731+
});
17031732
});

0 commit comments

Comments
 (0)