Skip to content

Commit

Permalink
Fix: Emit scale does not always pass events (#261)
Browse files Browse the repository at this point in the history
* Fix: fancy destructure no bueno
* Update: async unit tests
* Update: pr feedback
  • Loading branch information
Minh-Ng authored Jul 29, 2017
1 parent b7cde84 commit 41b1af0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ class BaseViewer extends EventEmitter {
document.defaultView.addEventListener('resize', this.debouncedResizeHandler);

this.addListener('load', (event) => {
({ scale: this.scale = 1 } = event);
if (event && event.scale) {
this.scale = event.scale;
}

if (this.annotationsPromise) {
this.annotationsPromise.then(this.loadAnnotator);
Expand Down
34 changes: 34 additions & 0 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,40 @@ describe('lib/viewers/BaseViewer', () => {
expect(document.defaultView.addEventListener).to.be.calledWith('resize', base.debouncedResizeHandler);
expect(base.addListener).to.be.calledWith('load', sinon.match.func);
});

it('should load the annotator when load is emitted with scale', (done) => {
sandbox.stub(fullscreen, 'addListener');
sandbox.stub(document.defaultView, 'addEventListener');
sandbox.stub(base, 'loadAnnotator');
base.annotationsPromise = {
then: (arg) => {
expect(base.scale).to.equal(1.5);
expect(arg).to.equal(base.loadAnnotator);
done();
}
};

base.addCommonListeners();
expect(base.scale).to.equal(1);
base.emit('load', {
scale: 1.5
});
});

it('should load the annotator when load is emitted without an event', (done) => {
sandbox.stub(fullscreen, 'addListener');
sandbox.stub(document.defaultView, 'addEventListener');
sandbox.stub(base, 'loadAnnotator');
base.annotationsPromise = {
then: (arg) => {
expect(arg).to.equal(base.loadAnnotator);
done();
}
};

base.addCommonListeners();
base.emit('load');
});
});

describe('toggleFullscreen()', () => {
Expand Down

0 comments on commit 41b1af0

Please sign in to comment.