From 7dff8f98de6beb90d1797de97cb18495294eb208 Mon Sep 17 00:00:00 2001 From: Conrad Chan Date: Tue, 18 Aug 2020 22:57:53 -0700 Subject: [PATCH] chore: pr comments --- src/BoxAnnotations.ts | 5 +++++ src/__tests__/BoxAnnotations-test.js | 3 ++- src/common/BaseAnnotator.ts | 9 +++------ src/common/__tests__/BaseAnnotator-test.ts | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/BoxAnnotations.ts b/src/BoxAnnotations.ts index 0008ef46b..569cb223b 100644 --- a/src/BoxAnnotations.ts +++ b/src/BoxAnnotations.ts @@ -12,9 +12,14 @@ type Annotator = { }; type AnnotationsOptions = { + features: Features; intl: IntlOptions; }; +export type Features = { + [key: string]: boolean; +}; + type PreviewOptions = { file?: { permissions?: Permissions; diff --git a/src/__tests__/BoxAnnotations-test.js b/src/__tests__/BoxAnnotations-test.js index b15230d2a..7ee49e314 100644 --- a/src/__tests__/BoxAnnotations-test.js +++ b/src/__tests__/BoxAnnotations-test.js @@ -153,7 +153,8 @@ describe('BoxAnnotations', () => { }); describe('getOptions', () => { - it.each([undefined, { intl: { messages: { test: 'Hello' } } }])( + const features = { enabledFeature: true }; + test.each([undefined, { features, intl: { messages: { test: 'Hello' } } }])( 'should return the passed in options when they are %o', mockOptions => { loader = new BoxAnnotations(null, mockOptions); diff --git a/src/common/BaseAnnotator.ts b/src/common/BaseAnnotator.ts index 1ee1f4386..5a3e8b55b 100644 --- a/src/common/BaseAnnotator.ts +++ b/src/common/BaseAnnotator.ts @@ -6,14 +6,11 @@ import EventEmitter from './EventEmitter'; import i18n from '../utils/i18n'; import messages from '../messages'; import { Event, IntlOptions, LegacyEvent, Permissions } from '../@types'; +import { Features } from '../BoxAnnotations'; import './BaseAnnotator.scss'; export type Container = string | HTMLElement; -export type Features = { - [key: string]: boolean; -}; - export type FileOptions = { [key: string]: { annotations?: { @@ -58,7 +55,7 @@ export default class BaseAnnotator extends EventEmitter { store: store.AppStore; - constructor({ apiHost, container, features = {}, file, fileOptions, intl, token }: Options) { + constructor({ apiHost, container, features, file, fileOptions, intl, token }: Options) { super(); const fileOptionsValue = fileOptions?.[file.id]; @@ -79,7 +76,7 @@ export default class BaseAnnotator extends EventEmitter { }; this.container = container; - this.features = features; + this.features = features || {}; this.intl = i18n.createIntlProvider(intl); this.store = store.createStore(initialState, { api: new API({ apiHost, token }), diff --git a/src/common/__tests__/BaseAnnotator-test.ts b/src/common/__tests__/BaseAnnotator-test.ts index 357016d06..8659d0fee 100644 --- a/src/common/__tests__/BaseAnnotator-test.ts +++ b/src/common/__tests__/BaseAnnotator-test.ts @@ -262,8 +262,8 @@ describe('BaseAnnotator', () => { describe('isFeatureEnabled()', () => { test('should return whether feature is enabled or not', () => { - expect(annotator.isFeatureEnabled('enabledFeature')).toBeTruthy(); - expect(annotator.isFeatureEnabled('notEnabledFeature')).toBeFalsy(); + expect(annotator.isFeatureEnabled('enabledFeature')).toBe(true); + expect(annotator.isFeatureEnabled('notEnabledFeature')).toBe(false); }); }); });