mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Merge pull request #3992 from w33ble/fix/reflow-cleanup
ResizeChecker - fix call to reflowWatcher.off
This commit is contained in:
commit
27c03b7e67
2 changed files with 44 additions and 39 deletions
|
@ -198,7 +198,7 @@ define(function (require) {
|
|||
* @return {void}
|
||||
*/
|
||||
ResizeChecker.prototype.destroy = function () {
|
||||
reflowWatcher.off('reflow', this.check);
|
||||
reflowWatcher.off('reflow', this.onReflow);
|
||||
clearTimeout(this._timerId);
|
||||
};
|
||||
|
||||
|
|
|
@ -11,23 +11,24 @@ define(function (require) {
|
|||
var EventEmitter;
|
||||
var checker;
|
||||
var reflowWatcher;
|
||||
var spyReflowOn;
|
||||
var reflowSpies = {};
|
||||
|
||||
beforeEach(module('kibana'));
|
||||
|
||||
beforeEach(inject(function (Private) {
|
||||
window.DISABLE_RESIZE_CHECKER = false;
|
||||
ResizeChecker = Private(require('components/vislib/lib/resize_checker'));
|
||||
EventEmitter = Private(require('factories/events'));
|
||||
reflowWatcher = Private(require('components/reflow_watcher'));
|
||||
reflowSpies.on = sinon.spy(reflowWatcher, 'on');
|
||||
reflowSpies.off = sinon.spy(reflowWatcher, 'off');
|
||||
|
||||
spyReflowOn = sinon.spy(reflowWatcher, 'on');
|
||||
checker = new ResizeChecker(
|
||||
$(document.createElement('div'))
|
||||
.appendTo('body')
|
||||
.css('visibility', 'hidden')
|
||||
.get(0)
|
||||
);
|
||||
spyReflowOn.restore();
|
||||
var $el = $(document.createElement('div'))
|
||||
.appendTo('body')
|
||||
.css('visibility', 'hidden')
|
||||
.get(0);
|
||||
|
||||
checker = new ResizeChecker($el);
|
||||
}));
|
||||
|
||||
afterEach(function () {
|
||||
|
@ -36,23 +37,25 @@ define(function (require) {
|
|||
checker.destroy();
|
||||
});
|
||||
|
||||
it('is an event emitter', function () {
|
||||
expect(checker).to.be.a(EventEmitter);
|
||||
});
|
||||
|
||||
it('emits a "resize" event when the el is resized', function (done) {
|
||||
checker.on('resize', function () {
|
||||
done();
|
||||
describe('basic functionality', function () {
|
||||
it('is an event emitter', function () {
|
||||
expect(checker).to.be.a(EventEmitter);
|
||||
});
|
||||
|
||||
checker.$el.text('haz contents');
|
||||
checker.check();
|
||||
});
|
||||
it('listens for the "reflow" event of the reflowWatchers', function () {
|
||||
expect(reflowSpies.on).to.have.property('callCount', 1);
|
||||
var call = reflowSpies.on.getCall(0);
|
||||
expect(call.args[0]).to.be('reflow');
|
||||
});
|
||||
|
||||
it('listens for the "reflow" event of the reflowWatchers', function () {
|
||||
expect(spyReflowOn).to.have.property('callCount', 1);
|
||||
var call = spyReflowOn.getCall(0);
|
||||
expect(call.args[0]).to.be('reflow');
|
||||
it('emits a "resize" event when the el is resized', function (done) {
|
||||
checker.on('resize', function () {
|
||||
done();
|
||||
});
|
||||
|
||||
checker.$el.text('haz contents');
|
||||
checker.check();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#read', function () {
|
||||
|
@ -142,6 +145,23 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#destroy()', function () {
|
||||
it('removes the "reflow" event from the reflowWatcher', function () {
|
||||
var onCall = reflowSpies.on.getCall(0);
|
||||
var handler = onCall.args[1];
|
||||
|
||||
checker.destroy();
|
||||
expect(reflowSpies.off).to.have.property('callCount', 1);
|
||||
expect(reflowSpies.off.calledWith('reflow', handler)).to.be.ok();
|
||||
});
|
||||
|
||||
it('clears the timeout', function () {
|
||||
var spy = sinon.spy(window, 'clearTimeout');
|
||||
checker.destroy();
|
||||
expect(spy).to.have.property('callCount', 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('scheduling', function () {
|
||||
var clock;
|
||||
var schedule;
|
||||
|
@ -182,20 +202,5 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#destroy()', function () {
|
||||
it('removes the "reflow" event from the reflowWatcher', function () {
|
||||
var stub = sinon.stub(reflowWatcher, 'off');
|
||||
checker.destroy();
|
||||
expect(stub).to.have.property('callCount', 1);
|
||||
expect(stub.calledWith('reflow')).to.be.ok();
|
||||
});
|
||||
|
||||
it('clears the timeout', function () {
|
||||
var spy = sinon.spy(window, 'clearTimeout');
|
||||
checker.destroy();
|
||||
expect(spy).to.have.property('callCount', 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue