gristlabs_grist-core/test/client/lib/koDomScrolly.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

const {Scrolly} = require('app/client/lib/koDomScrolly');
const clientUtil = require('../clientUtil');
const G = require('app/client/lib/browserGlobals').get('window', '$');
const sinon = require('sinon');
const assert = require('assert');
/* global describe, it, after, before, beforeEach */
describe("koDomScrolly", function() {
clientUtil.setTmpMochaGlobals();
before(function(){
sinon.stub(Scrolly.prototype, 'scheduleUpdateSize');
});
beforeEach(function(){
Scrolly.prototype.scheduleUpdateSize.reset();
});
after(function(){
Scrolly.prototype.scheduleUpdateSize.restore();
});
it("should not remove other's resize handlers", function(){
let scrolly1 = createScrolly(),
scrolly2 = createScrolly();
G.$(G.window).trigger("resize");
let updateSpy = Scrolly.prototype.scheduleUpdateSize;
sinon.assert.called(updateSpy);
sinon.assert.calledOn(updateSpy, scrolly1);
sinon.assert.calledOn(updateSpy, scrolly2);
scrolly2.dispose();
updateSpy.reset();
G.$(G.window).trigger("resize");
assert.deepEqual(updateSpy.thisValues, [scrolly1]);
});
});
function createScrolly() {
// subscribe should return a disposable subscription.
const dispose = () => {};
const subscription = { dispose };
const data = {subscribe: () => subscription, all: () => []};
return new Scrolly(data);
}