1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-30 22:21:13 +03:00

Fix cleanup of resize events

This commit is contained in:
Joe Fiorini 2015-01-29 14:20:39 -05:00
parent f1f15f1670
commit e28869c63d
3 changed files with 29 additions and 7 deletions

View File

@ -15,13 +15,18 @@ angular.module('DashboardGraphs').
createGraph(data.hosts, data.license);
});
function onResize() {
if(!license_graph) return;
adjustGraphSize(license_graph, element);
}
angular.element($window).on('resize', function(e) {
if(!license_graph) return;
adjustGraphSize(license_graph, element);
});
element.on('$destroy', function() {
angular.element($window).off('resize', adjustGraphSize);
angular.element($window).off('resize', onResize);
});

View File

@ -109,15 +109,16 @@ angular.module('DashboardGraphs')
});
adjustGraphSize(job_status_chart, element);
}
angular.element($window).on('resize', function() {
function onResize() {
adjustGraphSize(job_status_chart, element);
});
}
angular.element($window).on('resize', onResize);
element.on('$destroy', function() {
angular.element($window).off('resize', adjustGraphSize);
angular.element($window).off('resize', onResize);
});
if (scope.removeGraphDataReady) {

View File

@ -1,10 +1,13 @@
describe('Job Status Graph Directive', function() {
var element, scope, httpBackend;
var resizeHandler = sinon.spy();
beforeEach(module('Tower'));
beforeEach(module(function($provide) {
$provide.value('LoadBasePaths', angular.noop);
$provide.value('adjustGraphSize', resizeHandler);
}));
beforeEach(inject(function($rootScope, $compile, $httpBackend) {
@ -36,8 +39,9 @@ describe('Job Status Graph Directive', function() {
}));
afterEach(function() {
httpBackend.verifyNoOutstandingExpectation();
httpBackend.verifyNoOutstandingRequest();
element.trigger('$destroy');
httpBackend.verifyNoOutstandingExpectation();
httpBackend.verifyNoOutstandingRequest();
});
function filterDataSeries(key, data) {
@ -68,5 +72,17 @@ describe('Job Status Graph Directive', function() {
{x: 5, y: 0, series: 1}]);
});
it('cleans up external bindings', function() {
element.trigger('$destroy');
resizeHandler.reset();
inject(['$window', function($window) {
angular.element($window).trigger('resize');
}]);
expect(resizeHandler).not.to.have.been.called;
});
});