-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #814 from eclarizio/BZ1439761
Fix for service catalog service dialog refresh function behaving differently
- Loading branch information
Showing
11 changed files
with
293 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** @ngInject */ | ||
export function AutoRefreshFactory() { | ||
const callbacks = []; | ||
const service = { | ||
triggerAutoRefresh: triggerAutoRefresh, | ||
listenForAutoRefresh: listenForAutoRefresh, | ||
callbacks: callbacks, | ||
}; | ||
|
||
function triggerAutoRefresh(data) { | ||
callbacks.forEach((callback) => { | ||
callback(data); | ||
}); | ||
} | ||
|
||
function listenForAutoRefresh(allDialogFields, autoRefreshableDialogFields, url, resourceId, refreshCallback) { | ||
const nextFieldToRefresh = function(field, data, currentIndex) { | ||
return (field.auto_refresh === true && data.initializingIndex !== currentIndex && data.currentIndex < currentIndex); | ||
}; | ||
|
||
const listenerFunction = function(data) { | ||
const autoRefreshOptions = { | ||
initializingIndex: data.initializingIndex, | ||
}; | ||
|
||
const dialogFieldToRefresh = autoRefreshableDialogFields.filter(function(field, currentIndex) { | ||
if (nextFieldToRefresh(field, data, currentIndex)) { | ||
return field; | ||
} | ||
}); | ||
|
||
if (dialogFieldToRefresh.length > 0) { | ||
dialogFieldToRefresh[0].beingRefreshed = true; | ||
dialogFieldToRefresh[0].triggerOverride = true; | ||
autoRefreshOptions.currentIndex = dialogFieldToRefresh[0].refreshableFieldIndex; | ||
refreshCallback(allDialogFields, dialogFieldToRefresh[0], url, resourceId, autoRefreshOptions); | ||
} | ||
}; | ||
|
||
callbacks.push(listenerFunction); | ||
} | ||
|
||
return service; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
describe('AutoRefresh Service', function() { | ||
beforeEach(function() { | ||
module('app.services'); | ||
bard.inject('AutoRefresh'); | ||
}); | ||
|
||
describe('#triggerAutoRefresh', function() { | ||
var testFunction = sinon.stub(); | ||
|
||
beforeEach(function() { | ||
AutoRefresh.callbacks.push(testFunction); | ||
}); | ||
|
||
it('calls all of the callbacks passing the data through', function() { | ||
AutoRefresh.triggerAutoRefresh('the data'); | ||
expect(testFunction).to.have.been.calledWith('the data'); | ||
}); | ||
}); | ||
|
||
describe('#listenForAutoRefresh', function() { | ||
var listenerFunction; | ||
var refreshCallback = sinon.stub(); | ||
var allDialogFields = 'alldialogfields'; | ||
var url = 'url'; | ||
var resourceId = 'resourceid'; | ||
var dialog1 = {}; | ||
var dialog2 = {auto_refresh: true, refreshableFieldIndex: 123}; | ||
var autoRefreshableDialogFields = [dialog1, dialog2]; | ||
|
||
beforeEach(function() { | ||
AutoRefresh.listenForAutoRefresh(allDialogFields, autoRefreshableDialogFields, url, resourceId, refreshCallback); | ||
listenerFunction = AutoRefresh.callbacks[0]; | ||
}); | ||
|
||
describe('#listenForAutoRefresh listenerFunction', function() { | ||
describe('when the list of fields to refresh is greater than 0', function() { | ||
var data = {initializingIndex: 0, currentIndex: 0}; | ||
|
||
beforeEach(function() { | ||
listenerFunction(data); | ||
}); | ||
|
||
it('sets the beingRefreshed property on the dialog field to true', function() { | ||
expect(dialog2.beingRefreshed).to.equal(true); | ||
}); | ||
|
||
it('sets the triggerOverride property on the dialog field to true', function() { | ||
expect(dialog2.triggerOverride).to.equal(true); | ||
}); | ||
|
||
it('calls the refresh callback with the right arugments', function() { | ||
var autoRefreshOptions = {currentIndex: 123, initializingIndex: 0}; | ||
|
||
expect(refreshCallback).to.have.been.calledWith( | ||
'alldialogfields', dialog2, 'url', 'resourceid', autoRefreshOptions | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.