-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When the X-Icinga-Module-Enable header is send, the modulemanager automatically tries to load javascript files for that module. This is realized by adding the 'registerHeaderListener' method to the async manager, which allows to listen to specific headers and firing callbacks if a response with the specified header is retrieved. Also the tests have changed a bit, requireNow should be used when using the requiremock, so a require always loads files new. refs #4092 refs #3753
- Loading branch information
Jannis Moßhammer
committed
Jun 21, 2013
1 parent
36c8e0d
commit 35c4344
Showing
7 changed files
with
179 additions
and
14 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
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
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,35 @@ | ||
|
||
// {{LICENSE_HEADER}} | ||
// {{LICENSE_HEADER}} | ||
var should = require("should"); | ||
var rjsmock = require("requiremock.js"); | ||
var asyncMock = require("asyncmock.js"); | ||
|
||
GLOBAL.document = $('body'); | ||
|
||
|
||
describe('The async module', function() { | ||
it("Allows to react on specific headers", function(done) { | ||
rjsmock.purgeDependencies(); | ||
rjsmock.registerDependencies({ | ||
'icinga/container' : { | ||
updateContainer : function() {}, | ||
createPopupContainer: function() {} | ||
} | ||
}); | ||
|
||
requireNew("icinga/util/async.js"); | ||
var async = rjsmock.getDefine(); | ||
var headerValue = null; | ||
asyncMock.setNextAsyncResult(async, "result", false, { | ||
'X-Dont-Care' : 'Ignore-me', | ||
'X-Test-Header' : 'Testme123' | ||
}); | ||
async.registerHeaderListener("X-Test-Header", function(value, header) { | ||
should.equal("Testme123", value); | ||
done(); | ||
},this); | ||
var test = async.createRequest(); | ||
}); | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Helper for mocking $.async's XHR requests | ||
* | ||
*/ | ||
|
||
|
||
var getCallback = function(empty, response, succeed, headers) { | ||
if (empty) | ||
return function() {}; | ||
return function(callback) { | ||
callback(response, succeed, { | ||
getAllResponseHeaders: function() { | ||
return headers; | ||
}, | ||
getResponseHeader: function(header) { | ||
return headers[header] || null; | ||
} | ||
}); | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
setNextAsyncResult: function(async, response, fails, headers) { | ||
headers = headers || {}; | ||
var succeed = fails ? "fail" : "success"; | ||
async.__internalXHRImplementation = function(config) { | ||
return { | ||
done: getCallback(fails, response, succeed, headers), | ||
fail: getCallback(!fails, response, succeed, headers) | ||
}; | ||
}; | ||
} | ||
}; |
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