mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
Fix cleanup of resize events
This commit is contained in:
@@ -15,13 +15,18 @@ angular.module('DashboardGraphs').
|
|||||||
createGraph(data.hosts, data.license);
|
createGraph(data.hosts, data.license);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function onResize() {
|
||||||
|
if(!license_graph) return;
|
||||||
|
adjustGraphSize(license_graph, element);
|
||||||
|
}
|
||||||
|
|
||||||
angular.element($window).on('resize', function(e) {
|
angular.element($window).on('resize', function(e) {
|
||||||
if(!license_graph) return;
|
if(!license_graph) return;
|
||||||
adjustGraphSize(license_graph, element);
|
adjustGraphSize(license_graph, element);
|
||||||
});
|
});
|
||||||
|
|
||||||
element.on('$destroy', function() {
|
element.on('$destroy', function() {
|
||||||
angular.element($window).off('resize', adjustGraphSize);
|
angular.element($window).off('resize', onResize);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -109,15 +109,16 @@ angular.module('DashboardGraphs')
|
|||||||
});
|
});
|
||||||
|
|
||||||
adjustGraphSize(job_status_chart, element);
|
adjustGraphSize(job_status_chart, element);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
angular.element($window).on('resize', function() {
|
function onResize() {
|
||||||
adjustGraphSize(job_status_chart, element);
|
adjustGraphSize(job_status_chart, element);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
angular.element($window).on('resize', onResize);
|
||||||
|
|
||||||
element.on('$destroy', function() {
|
element.on('$destroy', function() {
|
||||||
angular.element($window).off('resize', adjustGraphSize);
|
angular.element($window).off('resize', onResize);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (scope.removeGraphDataReady) {
|
if (scope.removeGraphDataReady) {
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
describe('Job Status Graph Directive', function() {
|
describe('Job Status Graph Directive', function() {
|
||||||
var element, scope, httpBackend;
|
var element, scope, httpBackend;
|
||||||
|
|
||||||
|
var resizeHandler = sinon.spy();
|
||||||
|
|
||||||
beforeEach(module('Tower'));
|
beforeEach(module('Tower'));
|
||||||
|
|
||||||
beforeEach(module(function($provide) {
|
beforeEach(module(function($provide) {
|
||||||
$provide.value('LoadBasePaths', angular.noop);
|
$provide.value('LoadBasePaths', angular.noop);
|
||||||
|
$provide.value('adjustGraphSize', resizeHandler);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(inject(function($rootScope, $compile, $httpBackend) {
|
beforeEach(inject(function($rootScope, $compile, $httpBackend) {
|
||||||
@@ -36,8 +39,9 @@ describe('Job Status Graph Directive', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
httpBackend.verifyNoOutstandingExpectation();
|
element.trigger('$destroy');
|
||||||
httpBackend.verifyNoOutstandingRequest();
|
httpBackend.verifyNoOutstandingExpectation();
|
||||||
|
httpBackend.verifyNoOutstandingRequest();
|
||||||
});
|
});
|
||||||
|
|
||||||
function filterDataSeries(key, data) {
|
function filterDataSeries(key, data) {
|
||||||
@@ -68,5 +72,17 @@ describe('Job Status Graph Directive', function() {
|
|||||||
{x: 5, y: 0, series: 1}]);
|
{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;
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user