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

Commit 65f7ce7

Browse files
committed
Add test
1 parent 2c4204e commit 65f7ce7

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
@@ -1288,7 +1288,7 @@
12881288
$select.disableChoiceExpression = attrs.uiDisableChoice;
12891289
$select.onHighlightCallback = attrs.onHighlight;
12901290

1291-
$select.refreshOnActive = attrs.refreshOnActive;
1291+
$select.refreshOnActive = scope.$eval(attrs.refreshOnActive);
12921292

12931293
if(groupByExp) {
12941294
var groups = element.querySelectorAll('.ui-select-choices-group');
@@ -1315,13 +1315,13 @@
13151315
scope.$watch('$select.search', function(newValue) {
13161316
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
13171317
$select.activeIndex = $select.tagging.isActivated ? -1 : 0;
1318-
if(angular.isUndefined($select.refreshOnActive) || ($select.refreshOnActive && $select.refreshIsActive)) {
1318+
if(!$select.refreshOnActive || ($select.refreshOnActive && $select.refreshIsActive)) {
13191319
$select.refresh(attrs.refresh);
13201320
}
13211321
});
13221322

1323-
scope.$watch('$select.refreshIsActive', function(value){
1324-
if(angular.isUndefined(value)){
1323+
scope.$watch('$select.refreshIsActive', function(newValue, oldValue){
1324+
if(angular.isUndefined(oldValue) && newValue){
13251325
$select.refresh(attrs.refresh);
13261326
}
13271327
});

test/select.spec.js

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

192192
expect(getMatchLabel(el)).toEqual('Adam');
193193
});
194-
194+
195195
it('should correctly render initial state with track by feature', function() {
196196
var el = compileTemplate(
197197
'<ui-select ng-model="selection.selected"> \
@@ -1791,4 +1791,33 @@ describe('ui-select tests', function() {
17911791
}
17921792
});
17931793
});
1794+
1795+
describe('with refresh on active', function(){
1796+
it('should not refresh untill is activate', function(){
1797+
1798+
var el = compileTemplate(
1799+
'<ui-select ng-model="selection.selected"> \
1800+
<ui-select-match> \
1801+
</ui-select-match> \
1802+
<ui-select-choices repeat="person in people | filter: $select.search" \
1803+
refresh="fetchFromServer($select.search)" refresh-on-active="true" refresh-delay="0"> \
1804+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1805+
<div ng-if="person.name==\'Wladimir\'"> \
1806+
<span class="only-once">I should appear only once</span>\
1807+
</div> \
1808+
</ui-select-choices> \
1809+
</ui-select>'
1810+
);
1811+
1812+
scope.fetchFromServer = function(){};
1813+
spyOn(scope, 'fetchFromServer');
1814+
$timeout.flush();
1815+
expect(scope.fetchFromServer.calls.any()).toEqual(false);
1816+
1817+
el.scope().$select.activate();
1818+
$timeout.flush();
1819+
expect(scope.fetchFromServer.calls.any()).toEqual(true);
1820+
});
1821+
1822+
});
17941823
});

0 commit comments

Comments
 (0)