Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
feat(Scenario): autodisable animations when running e2e tests
Browse files Browse the repository at this point in the history
animations cause the dom to contain elements that have been removed
from the model but are being animated out.

we could teach the e2e runner to wait for animations but that would
make all tests slower. it should be quite safe to just disable
animations automatically when the app is running via the e2e test
runner.

this change disables only css animations. we should make additional
change that disables js animations as well, but since we don't need
this right now I'm punting on it.
  • Loading branch information
IgorMinar committed Apr 4, 2013
1 parent ecdf119 commit fec4ef3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/bootstrap/bootstrap-prettify.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ directive.ngEvalJavascript = ['getEmbeddedTemplate', function(getEmbeddedTemplat
}];


directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location', function($templateCache, $browser, docsRootScope, $location) {
directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location', '$sniffer',
function($templateCache, $browser, docsRootScope, $location, $sniffer) {
return {
terminal: true,
link: function(scope, element, attrs) {
Expand All @@ -189,6 +190,7 @@ directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location',
$provide.value('$templateCache', $templateCache);
$provide.value('$anchorScroll', angular.noop);
$provide.value('$browser', $browser);
$provide.value('$sniffer', $sniffer);
$provide.provider('$location', function() {
this.$get = ['$rootScope', function($rootScope) {
docsRootScope.$on('$locationChangeSuccess', function(event, oldUrl, newUrl) {
Expand Down Expand Up @@ -223,6 +225,7 @@ directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location',
event.preventDefault();
}
});

angular.bootstrap(element, modules);
}
};
Expand Down
28 changes: 23 additions & 5 deletions src/ngScenario/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,47 @@ angular.scenario.Application.prototype.getWindow_ = function() {
*/
angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorFn) {
var self = this;
var frame = this.getFrame_();
var frame = self.getFrame_();
//TODO(esprehn): Refactor to use rethrow()
errorFn = errorFn || function(e) { throw e; };
if (url === 'about:blank') {
errorFn('Sandbox Error: Navigating to about:blank is not allowed.');
} else if (url.charAt(0) === '#') {
url = frame.attr('src').split('#')[0] + url;
frame.attr('src', url);
this.executeAction(loadFn);
self.executeAction(loadFn);
} else {
frame.remove();
this.context.find('#test-frames').append('<iframe>');
frame = this.getFrame_();
self.context.find('#test-frames').append('<iframe>');
frame = self.getFrame_();

frame[0].contentWindow.name = "NG_DEFER_BOOTSTRAP!";

frame.load(function() {
frame.unbind();
try {
var $window = self.getWindow_();

if ($window.angular) {
// Disable animations

// TODO(i): this doesn't disable javascript animations
// we don't need that for our tests, but it should be done
$window.angular.resumeBootstrap([['$provide', function($provide) {
$provide.decorator('$sniffer', function($delegate) {
$delegate.supportsTransitions = false;
return $delegate;
});
}]]);
}

self.executeAction(loadFn);
} catch (e) {
errorFn(e);
}
}).attr('src', url);
}
this.context.find('> h2 a').attr('href', url).text(url);
self.context.find('> h2 a').attr('href', url).text(url);
};

/**
Expand Down
11 changes: 10 additions & 1 deletion test/ngScenario/ApplicationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ describe('angular.scenario.Application', function() {
}

beforeEach(function() {
document.body.innerHTML = '';
frames = _jQuery("<div></div>");
_jQuery(document.body).append(frames);
app = new angular.scenario.Application(frames);
});

it('should return new $window and $document after navigate', function() {

afterEach(function() {
_jQuery('iframe').unbind(); // cleanup any leftover onload handlers
document.body.innerHTML = '';
});


it('should return new $window and $document after navigateTo', function() {
var called;
var testWindow, testDocument, counter = 0;
app.getWindow_ = function() {
Expand Down

0 comments on commit fec4ef3

Please sign in to comment.