Skip to content

Commit

Permalink
chore(log): Add log for image zoom click
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Jul 10, 2020
1 parent ed77210 commit 92e94d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const VIEWER_EVENT = {
default: 'viewerevent', // The default viewer event.
download: 'download', // Begin downloading the file.
error: 'error', // When an error occurs.
imageZoomClick: 'imagezoomclick', // When image is clicked directly to zoom/reset
load: 'load', // Preview is finished loading.
mediaEndAutoplay: 'mediaendautoplay', // Media playback has completed, with autoplay enabled.
metric: 'viewermetric', // A viewer metric.
Expand Down
2 changes: 2 additions & 0 deletions src/lib/viewers/image/ImageBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ class ImageBaseViewer extends BaseViewer {
// click mouse up. In that case reset the image size, mimicking single-click-unzoom.
this.zoom('reset');
}

this.emitMetric(VIEWER_EVENT.imageZoomClick, this.options.file.id);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/lib/viewers/image/__tests__/ImageBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,15 @@ 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;
imageBase.options = {
file: {
id: 1,
},
};
});

it('should do nothing if incorrect click type', () => {
Expand All @@ -335,6 +341,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 +356,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('imagezoomclick', 1);
});

it('should reset zoom if mouseup was not due to end of panning', () => {
Expand All @@ -364,6 +372,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('imagezoomclick', 1);
});

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

0 comments on commit 92e94d7

Please sign in to comment.