Skip to content

Commit

Permalink
Chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Holdstock committed Feb 4, 2019
1 parent faf2731 commit ea72630
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Preview extends EventEmitter {
*/
destroy() {
// Log all load metrics
this.emitLoadMetrics();
this.emitLoadMetrics({});

// Destroy viewer
if (this.viewer && typeof this.viewer.destroy === 'function') {
Expand Down
24 changes: 16 additions & 8 deletions src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PreviewError from '../PreviewError';
import DownloadReachability from '../DownloadReachability';
import * as file from '../file';
import * as util from '../util';
import { API_HOST, CLASS_NAVIGATION_VISIBILITY, PERMISSION_PREVIEW } from '../constants';
import { API_HOST, CLASS_NAVIGATION_VISIBILITY, PERMISSION_PREVIEW, ENCODING_TYPES } from '../constants';
import { VIEWER_EVENT, ERROR_CODE, LOAD_METRIC, PREVIEW_METRIC } from '../events';
import Timer from '../Timer';

Expand Down Expand Up @@ -2320,7 +2320,7 @@ describe('lib/Preview', () => {
sandbox.stub(Timer, 'reset');
sandbox.stub(preview, 'emit');
preview.file = undefined;
preview.emitLoadMetrics();
preview.emitLoadMetrics({});
expect(Timer.reset).to.not.be.called;
expect(preview.emit).to.not.be.called;
});
Expand All @@ -2329,15 +2329,15 @@ describe('lib/Preview', () => {
preview.once(PREVIEW_METRIC, () => {
done();
});
preview.emitLoadMetrics();
preview.emitLoadMetrics({});
});

it('should emit a preview_metric event with event_name "load"', (done) => {
preview.once(PREVIEW_METRIC, (metric) => {
expect(metric.event_name).to.equal(LOAD_METRIC.previewLoadEvent);
done();
});
preview.emitLoadMetrics();
preview.emitLoadMetrics({});
});

it('should emit a preview_metric event where the value property equals the sum of all load events', (done) => {
Expand All @@ -2354,7 +2354,7 @@ describe('lib/Preview', () => {
expect(metric.value).to.equal(expectedTime);
done();
});
preview.emitLoadMetrics();
preview.emitLoadMetrics({});
});

it('should emit a preview_metric event with an object, with all of the proper load properties', (done) => {
Expand All @@ -2365,13 +2365,13 @@ describe('lib/Preview', () => {
expect(metric[LOAD_METRIC.fullDocumentLoadTime]).to.exist;
done();
});
preview.emitLoadMetrics();
preview.emitLoadMetrics({});
});

it('should reset the Timer', () => {
sandbox.stub(Timer, 'reset');
sandbox.stub(preview, 'emit');
preview.emitLoadMetrics();
preview.emitLoadMetrics({});
expect(Timer.reset).to.be.called;
expect(preview.emit).to.be.called;
});
Expand All @@ -2385,7 +2385,15 @@ describe('lib/Preview', () => {
expect(metric[LOAD_METRIC.fullDocumentLoadTime]).to.equal(0);
done();
});
preview.emitLoadMetrics();
preview.emitLoadMetrics({});
});

it('should append encoding field to load metric, when provided', (done) => {
preview.once(PREVIEW_METRIC, (metric) => {
expect(metric.encoding).to.equal(ENCODING_TYPES.GZIP);
done();
});
preview.emitLoadMetrics({ encoding: ENCODING_TYPES.GZIP });
});
});

Expand Down
2 changes: 2 additions & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1445,9 +1445,11 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
};
docBase.loaded = false;
docBase.pdfViewer.pagesCount = 5;
docBase.encoding = 'gzip';

docBase.pagesinitHandler();
expect(stubs.emit).to.be.calledWith(VIEWER_EVENT.load, {
encoding: docBase.encoding,
endProgress: false,
numPages: 5,
scale: sinon.match.any
Expand Down

0 comments on commit ea72630

Please sign in to comment.