Skip to content

Commit

Permalink
fix: withoutHOC regex by removing unused nonMemoized function
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Amalric committed Nov 28, 2023
1 parent d1b3484 commit 361cb60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 16 additions & 2 deletions packages/cmf/__tests__/settings.test.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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');
});
});
});
8 changes: 4 additions & 4 deletions packages/cmf/src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
}

/**
Expand Down

0 comments on commit 361cb60

Please sign in to comment.