diff --git a/src/components/Widget/Widget.test.tsx b/src/components/Widget/Widget.test.tsx index 869965e74..7f6354b1e 100644 --- a/src/components/Widget/Widget.test.tsx +++ b/src/components/Widget/Widget.test.tsx @@ -313,3 +313,55 @@ describe('Choose widget', () => { expect(wrapper.find('TextWidget').length).toBe(1) }) }) + +describe('Custom widget debug panel', () => { + let store: Store = null + + const widgetCustomMeta = { + id: '1', + name: '1', + type: 'MyCustom', + title: 'MyCustom title', + bcName: exampleBcName, + position: 1, + gridWidth: 1, + fields: [] as WidgetField[] + } + + function MyCustom() { + return
custom widget
+ } + + function MyCard({ children }: { children: any }) { + return
{children}
+ } + + beforeAll(() => { + store = mockStore() + store.getState().screen.bo.bc[exampleBcName] = {} as BcMetaState + store.getState().data[exampleBcName] = [{ id: '11111', vstamp: 1 }] + store.getState().session.debugMode = true + store.getState().view.widgets = [widgetCustomMeta] + }) + + it('should show debug panel for custom widget WITHOUT custom card', function () { + const wrapper = mount( + + + + ) + + expect(wrapper.find('Memo(DebugPanel)').length).toBe(1) + }) + + it('should show debug panel for custom widget WITH custom card', function () { + const wrapper = mount( + + + + ) + + expect(wrapper.find('Memo(DebugPanel)').length).toBe(1) + expect(wrapper.find('MyCard').length).toBe(1) + }) +}) diff --git a/src/components/Widget/Widget.tsx b/src/components/Widget/Widget.tsx index 1b79f2432..894e5b242 100644 --- a/src/components/Widget/Widget.tsx +++ b/src/components/Widget/Widget.tsx @@ -54,18 +54,6 @@ export const Widget: FunctionComponent = props => { return <> {chooseWidgetType(props.meta, props.customWidgets, props.children)} } - if (customWidget && !isCustomWidget(customWidget)) { - if (customWidget.card === null) { - return <> {chooseWidgetType(props.meta, props.customWidgets, props.children)} - } - - if (customWidget.card) { - const CustomCard = customWidget.card - - return {chooseWidgetType(props.meta, props.customWidgets, props.children)} - } - } - const showSpinner = !!(props.loading && (props.rowMetaExists || props.dataExists)) const showSkeleton = props.loading && !showSpinner @@ -78,22 +66,33 @@ export const Widget: FunctionComponent = props => { ) // TODO 2.0.0 delete spinner and skeleton. Spinner and skeleton should be overridden by props.card component + const WidgetParts = ( + <> + {showSkeleton && } + {!showSkeleton && spinnerElement} + {props.debugMode && } + + ) + + if (customWidget && !isCustomWidget(customWidget)) { + if (customWidget.card === null) { + return WidgetParts + } + + if (customWidget.card) { + const CustomCard = customWidget.card + return {WidgetParts} + } + } + if (props.card) { const Card = props.card - return ( - - {showSkeleton && } - {!showSkeleton && spinnerElement} - {props.debugMode && } - - ) + return {WidgetParts} } return (

{props.meta.title}

- {showSkeleton && } - {!showSkeleton && spinnerElement} - {props.debugMode && } + {WidgetParts}
) }