Skip to content

Commit

Permalink
Merge pull request blinkbox#1 from maciejblinkbox/blinkboxMaster
Browse files Browse the repository at this point in the history
e2e test runner can now test manually bootstrapped angularjs applications
  • Loading branch information
chrismilleruk committed Aug 8, 2012
2 parents 63e2c25 + 93e0724 commit a05e445
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions src/ngScenario/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,43 @@ angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorF
* @param {function()} action The callback to execute. function($window, $document)
* $document is a jQuery wrapped document.
*/
angular.scenario.Application.prototype.executeAction = function(action) {
var self = this;
var $window = this.getWindow_();
if (!$window.document) {
throw 'Sandbox Error: Application document not accessible.';
}
if (!$window.angular) {
return action.call(this, $window, _jQuery($window.document));
}
angularInit($window.document, function(element) {
var $injector = $window.angular.element(element).injector();
var $element = _jQuery(element);
angular.scenario.Application.prototype.executeAction = function(action)
{
var self = this;
var $window = this.getWindow_();
if (!$window.document) {
throw 'Sandbox Error: Application document not accessible.';
}

if (!$window.angular) {
return action.call(this, $window, _jQuery($window.document));
}

var initialisedWithNgAppDirective = false;

// angularInit calls this function only if ng-app directive is detected
var initFn = function(element) {
initialisedWithNgAppDirective = true;

var $injector = $window.angular.element(element).injector();
var $element = _jQuery(element);

$element.injector = function() {
return $injector;
};

$injector.invoke(function($browser) {
$browser.notifyWhenNoOutstandingRequests(function() {
action.call(self, $window, $element);
});
});
};

$element.injector = function() {
return $injector;
};
// original implementation searches for ng-app and attaches to angular if found
angularInit($window.document, initFn);

$injector.invoke(function($browser){
$browser.notifyWhenNoOutstandingRequests(function() {
action.call(self, $window, $element);
});
});
});
if (!initialisedWithNgAppDirective) {
// ng-app not found so manually attaching to the root of document
initFn($window.document);
}
};

0 comments on commit a05e445

Please sign in to comment.