diff --git a/packages/cmf/__tests__/settings.test.js b/packages/cmf/__tests__/settings.test.js index eb82e8482cf..129db6434bc 100644 --- a/packages/cmf/__tests__/settings.test.js +++ b/packages/cmf/__tests__/settings.test.js @@ -1,7 +1,14 @@ -import { render, screen } from '@testing-library/react'; import { Provider } from 'react-redux'; -import { generateDefaultViewId, mapStateToViewProps, WaitForSettings } from '../src/settings'; + +import { render, screen } from '@testing-library/react'; + import { mock } from '../src'; +import { + generateDefaultViewId, + mapStateToViewProps, + WaitForSettings, + withoutHOC, +} from '../src/settings'; describe('settings', () => { describe('mapStateToViewProps', () => { @@ -62,6 +69,7 @@ describe('settings', () => { expect(generateDefaultViewId()).toBe(undefined); }); }); + describe('WaitForSettings', () => { it('should display using loader if state settings is not initialized', () => { const state = mock.store.state(); @@ -99,4 +107,10 @@ describe('settings', () => { expect(() => screen.getByText('loading')).toThrow(); }); }); + + describe('withoutHOC', () => { + it('should remove all HOC prefix', () => { + expect(withoutHOC('Connect(CMF(Container(MyComponent)))')).toBe('MyComponent'); + }); + }); }); diff --git a/packages/cmf/src/settings.js b/packages/cmf/src/settings.js index b17a0d5178b..d9fe6171b9d 100644 --- a/packages/cmf/src/settings.js +++ b/packages/cmf/src/settings.js @@ -2,9 +2,10 @@ * Internal. All stuff related to the settings handling in CMF. * @module react-cmf/lib/settings */ -import PropTypes from 'prop-types'; import { connect } from 'react-redux'; + import memoize from 'lodash/memoize'; +import PropTypes from 'prop-types'; /** * if viewId is undefined, try to generate a meaningfull one @@ -29,9 +30,8 @@ export function generateDefaultViewId(viewId, componentName, componentId) { * @param {String} viewId Connect(CMF(Container(MyComponent))) * @return {String} MyComponent */ -function withoutHOC(componentName) { - const match = componentName.match(/\(([^)]+)\)/); - return match ? match[1] : null; +export function withoutHOC(componentName) { + return componentName.match(/.*\((.*?)\)/)[1]; } /**