diff --git a/src/lib/Preview.js b/src/lib/Preview.js index 773de069a..afeb4bb0f 100644 --- a/src/lib/Preview.js +++ b/src/lib/Preview.js @@ -66,6 +66,7 @@ import { VIEWER_EVENT, } from './events'; import { getClientLogDetails, getISOTime } from './logUtils'; +import { isFeatureEnabled } from './featureChecking'; import './Preview.scss'; const DEFAULT_DISABLED_VIEWERS = ['Office']; // viewers disabled by default @@ -1001,9 +1002,6 @@ class Preview extends EventEmitter { // Add the response interceptor to the preview instance this.options.responseInterceptor = options.responseInterceptor; - // Advanced Content Insights - this.options.advancedContentInsights = options.advancedContentInsights; - // Features // This makes features available everywhere that features is passed in, which includes // all of the viewers for different files @@ -1439,7 +1437,9 @@ class Preview extends EventEmitter { this.api .post(`${apiHost}/2.0/events`, data, { headers }) .then(() => { - this.pageTrackerReporter(true); + if (isFeatureEnabled(this.options.features, 'advancedContentInsights.enabled')) { + this.pageTrackerReporter(true); + } // Reset retry count after successfully logging this.logRetryCount = 0; }) @@ -1447,7 +1447,9 @@ class Preview extends EventEmitter { // Don't retry more than the retry limit this.logRetryCount += 1; if (this.logRetryCount > LOG_RETRY_COUNT) { - this.pageTrackerReporter(false); + if (isFeatureEnabled(this.options.features, 'advancedContentInsights.enabled')) { + this.pageTrackerReporter(false); + } this.logRetryCount = 0; clearTimeout(this.logRetryTimeout); return; @@ -1841,13 +1843,17 @@ class Preview extends EventEmitter { * Updates advanced content insights options after props have changed in parent app * * @public - * @param {Object} options - new content insights options value + * @param {Object} newOptions - new content insights options value * @return {void} */ - updateContentInsightsOptions(options) { + updateContentInsightsOptions(newOptions) { + this.options.features = { ...this.options.features, advancedContentInsights: newOptions }; if (this.viewer && this.viewer.pageTracker) { - this.previewOptions = { ...this.previewOptions, contentInsights: options }; - this.viewer.pageTracker.updateOptions(this.previewOptions.contentInsights); + this.previewOptions = { + ...this.previewOptions, + features: { ...this.previewOptions.features, advancedContentInsights: newOptions }, + }; + this.viewer.pageTracker.updateOptions(newOptions); } } diff --git a/src/lib/__tests__/Preview-test.js b/src/lib/__tests__/Preview-test.js index 0e0b64c5b..ab1c17630 100644 --- a/src/lib/__tests__/Preview-test.js +++ b/src/lib/__tests__/Preview-test.js @@ -13,6 +13,7 @@ import loaders from '../loaders'; import { API_HOST, CLASS_NAVIGATION_VISIBILITY, ENCODING_TYPES } from '../constants'; import { VIEWER_EVENT, ERROR_CODE, LOAD_METRIC, PREVIEW_METRIC } from '../events'; import PageTracker from '../PageTracker'; +import { isFeatureEnabled } from '../featureChecking'; jest.mock('../Logger'); jest.mock('../util', () => ({ @@ -25,6 +26,7 @@ jest.mock('../util', () => ({ }), getHeaders: jest.fn(), })); +jest.mock('../featureChecking'); const tokens = require('../tokens'); @@ -2109,18 +2111,34 @@ describe('lib/Preview', () => { }); }); - test('should fire the preview_event_report success event on a successful access stats post', () => { + test('should fire the preview_event_report success event on a successful access stats post if aci enabled', () => { preview.viewer = { emit: jest.fn(), }; + isFeatureEnabled.mockReturnValueOnce(true); stubs.emit = jest.spyOn(preview.viewer, 'emit'); jest.spyOn(Api.prototype, 'post').mockReturnValue(stubs.promiseResolve); preview.logPreviewEvent(0, {}); + return stubs.promiseResolve.then(() => { expect(stubs.emit).toBeCalledWith('preview_event_report', true); }); }); + test('should not fire the preview_event_report success event on a successful access stats post if aci disabled', () => { + preview.viewer = { + emit: jest.fn(), + }; + isFeatureEnabled.mockReturnValueOnce(false); + stubs.emit = jest.spyOn(preview.viewer, 'emit'); + jest.spyOn(Api.prototype, 'post').mockReturnValue(stubs.promiseResolve); + preview.logPreviewEvent(0, {}); + + return stubs.promiseResolve.then(() => { + expect(stubs.emit).not.toBeCalled(); + }); + }); + test('should fire the preview_event_report failed event if the post fails and retry limit has been reached', () => { preview.viewer = { emit: jest.fn(), @@ -2961,12 +2979,8 @@ describe('lib/Preview', () => { describe('updateContentInsightsOptions()', () => { test('should update the content insights options', () => { - preview.options = { - enableAdvancedContentInsights: true, - }; - - preview.previewOptions = { - contentInsights: { isActive: false }, + preview.previewOptions.features = { + advancedContentInsights: { isActive: false }, }; preview.viewer = { @@ -2977,7 +2991,9 @@ describe('lib/Preview', () => { const options = { isActive: true }; preview.updateContentInsightsOptions(options); - expect(preview.previewOptions.contentInsights).toBe(options); + + expect(preview.options.features.advancedContentInsights).toBe(options); + expect(preview.previewOptions.features.advancedContentInsights).toBe(options); expect(stubs.updateOptions).toBeCalledWith(options); }); }); diff --git a/src/lib/viewers/doc/DocBaseViewer.js b/src/lib/viewers/doc/DocBaseViewer.js index 3d20e9ce5..b7209d0c9 100644 --- a/src/lib/viewers/doc/DocBaseViewer.js +++ b/src/lib/viewers/doc/DocBaseViewer.js @@ -53,6 +53,7 @@ import { VIEWER_EVENT, } from '../../events'; import Timer from '../../Timer'; +import { getFeatureConfig, isFeatureEnabled } from '../../featureChecking'; export const DISCOVERABILITY_STATES = [ AnnotationState.HIGHLIGHT_TEMP, @@ -192,8 +193,11 @@ class DocBaseViewer extends BaseViewer { } this.updateDiscoverabilityResinTag(); - if (this.options.advancedContentInsights) { - this.pageTracker = new PageTracker(this.options.advancedContentInsights, this.options.file); + + const advancedContentInsightsConfig = getFeatureConfig(this.options.features, 'advancedContentInsights'); + + if (isFeatureEnabled(this.options.features, 'advancedContentInsights.enabled')) { + this.pageTracker = new PageTracker(advancedContentInsightsConfig, this.options.file); } } diff --git a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js index 815f18ac2..8f2a24550 100644 --- a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js +++ b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js @@ -269,7 +269,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { id: '0', extension: 'ppt', }, - advancedContentInsights: {}, + features: { advancedContentInsights: { enabled: true } }, }); docBase.containerEl = containerEl; docBase.rootEl = rootEl;