diff --git a/common/utils/__tests__/visualization_helpers.test.tsx b/common/utils/__tests__/visualization_helpers.test.tsx new file mode 100644 index 0000000000..6c7f9f8577 --- /dev/null +++ b/common/utils/__tests__/visualization_helpers.test.tsx @@ -0,0 +1,24 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { getUserConfigFrom } from '../visualization_helpers'; + +describe('Utils helper functions', () => { + describe('getUserConfigFrom', () => { + it('should return empty object from empty input', () => { + expect(getUserConfigFrom(undefined)).toEqual({}); + expect(getUserConfigFrom('')).toEqual({}); + expect(getUserConfigFrom({})).toEqual({}); + }); + it('should get object from user_configs json', () => { + const container = { user_configs: '{ "key": "value" }' }; + expect(getUserConfigFrom(container)).toEqual({ key: 'value' }); + }); + it('should get object from userConfigs', () => { + const container = { userConfigs: '{ "key": "value" }' }; + expect(getUserConfigFrom(container)).toEqual({ key: 'value' }); + }); + }); +}); diff --git a/common/utils/visualization_helpers.ts b/common/utils/visualization_helpers.ts new file mode 100644 index 0000000000..8a93cd7af3 --- /dev/null +++ b/common/utils/visualization_helpers.ts @@ -0,0 +1,19 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { isEmpty, isString } from 'lodash'; + +/* The file contains helper functions for visualizaitons operations + * getUserConfigFrom - returns input objects' user_configs or userConfigs, JSON parsed if necessary + */ + +export const getUserConfigFrom = (container: unknown): object => { + const config = container?.user_configs || container?.userConfigs || {}; + + if (isEmpty(config)) return {}; + + if (isString(config)) return JSON.parse(config); + else return {}; +}; diff --git a/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap b/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap new file mode 100644 index 0000000000..b8a95255af --- /dev/null +++ b/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap @@ -0,0 +1,910 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Explorer Search component renders basic component 1`] = ` + + +
+ +
+ +
+ + PPL + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="smallContextMenuExample" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > +
+
+ + + + + +
+
+
+
+
+ +
+ +
+ + +