Skip to content

Commit

Permalink
chore(log): Add log for image zoom click (#1234)
Browse files Browse the repository at this point in the history
* chore(log): Add log for image zoom click

* chore(log): Address comments
  • Loading branch information
Mingze authored Jul 14, 2020
1 parent ed77210 commit c29dddc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/viewers/image/ImageBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,12 @@ class ImageBaseViewer extends BaseViewer {
if (!this.isPannable && this.isZoomable) {
// If the mouse up was not due to panning, and the image is zoomable, then zoom in.
this.zoom('in');
this.emitMetric('zoom', 'inClick');
} else if (!this.didPan) {
// If the mouse up was not due to ending of panning, then assume it was a regular
// click mouse up. In that case reset the image size, mimicking single-click-unzoom.
this.zoom('reset');
this.emitMetric('zoom', 'resetClick');
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/viewers/image/__tests__/ImageBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => {

describe('handleMouseUp()', () => {
beforeEach(() => {
stubs.emitMetric = sandbox.stub(imageBase, 'emitMetric');
stubs.pan = sandbox.stub(imageBase, 'stopPanning');
stubs.zoom = sandbox.stub(imageBase, 'zoom');
imageBase.isPanning = false;
Expand All @@ -335,6 +336,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => {
event.metaKey = 'blah';
imageBase.handleMouseUp(event);
expect(stubs.zoom).to.not.have.been.called;
expect(stubs.emitMetric).to.not.have.been.called;
});

it('should zoom in if zoomable but not pannable', () => {
Expand All @@ -349,6 +351,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => {
imageBase.isZoomable = true;
imageBase.handleMouseUp(event);
expect(stubs.zoom).to.have.been.calledWith('in');
expect(stubs.emitMetric).to.be.calledWith('zoom', 'inClick');
});

it('should reset zoom if mouseup was not due to end of panning', () => {
Expand All @@ -364,6 +367,7 @@ describe('lib/viewers/image/ImageBaseViewer', () => {
imageBase.didPan = false;
imageBase.handleMouseUp(event);
expect(stubs.zoom).to.have.been.calledWith('reset');
expect(stubs.emitMetric).to.be.calledWith('zoom', 'resetClick');
});

it('should not zoom if mouse up was due to end of panning', () => {
Expand Down

0 comments on commit c29dddc

Please sign in to comment.