From b2d8ad1cd08fa76a78c128bbaf8cedce1f7a66b5 Mon Sep 17 00:00:00 2001 From: Bhargav Kodali Date: Fri, 22 Nov 2024 16:53:19 -0700 Subject: [PATCH 1/3] correct typo --- .../src/openmrsComponentDecorator.test.tsx | 32 +++++++++++++++++-- .../src/openmrsComponentDecorator.tsx | 4 +-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx b/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx index dd084c8d3..88605f8bc 100644 --- a/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx +++ b/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx @@ -1,5 +1,5 @@ -import React from 'react'; -import { render, screen, waitFor } from '@testing-library/react'; +import React, { Component } from 'react'; +import { render, screen, waitFor} from '@testing-library/react'; import { openmrsComponentDecorator } from './openmrsComponentDecorator'; import { ComponentContext } from './ComponentContext'; @@ -35,6 +35,22 @@ describe('openmrs-component-decorator', () => { const DecoratedComp = openmrsComponentDecorator(opts)(CompWithConfig); render(); }); + + it("rendering a unsafe component is strict mode should log error in console",()=>{ + const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {}); + const UnsafeDecoratedCompnent = openmrsComponentDecorator(opts)(UnsafeComponent); + render(); + expect(consoleError.mock.calls[0][0]).toContain('Warning: Using UNSAFE_componentWillMount'); + consoleError.mockRestore(); + }) + + it("rendering an unsafe component without strict mode should not log an error in console",()=>{ + const spy = jest.spyOn(console, "error"); + const unsafeComponentOptions=Object.assign(opts,{strictMode:false}) + const UnsafeDecoratedCompnent = openmrsComponentDecorator(unsafeComponentOptions)(UnsafeComponent); + render(); + expect(spy).not.toHaveBeenCalled(); + }) }); function CompThatWorks() { @@ -49,3 +65,15 @@ function CompWithConfig() { const { moduleName } = React.useContext(ComponentContext); return
{moduleName}
; } + + +class UnsafeComponent extends Component { + + UNSAFE_componentWillMount() { + + } + + render() { + return

This is Unsafe Component

; + } +}; diff --git a/packages/framework/esm-react-utils/src/openmrsComponentDecorator.tsx b/packages/framework/esm-react-utils/src/openmrsComponentDecorator.tsx index fc605f53b..ab8f6212c 100644 --- a/packages/framework/esm-react-utils/src/openmrsComponentDecorator.tsx +++ b/packages/framework/esm-react-utils/src/openmrsComponentDecorator.tsx @@ -120,8 +120,8 @@ export function openmrsComponentDecorator(userOpts: ComponentDecoratorOptions ); - - if (opts.strictMode || !React.StrictMode) { + + if (!opts.strictMode || !React.StrictMode) { return content; } else { return {content}; From cf821f3d95fa54d3e86f15f41de7eacbb1926d72 Mon Sep 17 00:00:00 2001 From: Bhargav Kodali Date: Fri, 22 Nov 2024 21:13:58 -0700 Subject: [PATCH 2/3] correct typo --- .../esm-react-utils/src/openmrsComponentDecorator.test.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx b/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx index 88605f8bc..14ef7a206 100644 --- a/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx +++ b/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx @@ -70,10 +70,9 @@ function CompWithConfig() { class UnsafeComponent extends Component { UNSAFE_componentWillMount() { - - } + } render() { return

This is Unsafe Component

; } -}; +} From 12ca31a4a65bb0c698cf1481b094e67b3b1f0137 Mon Sep 17 00:00:00 2001 From: Bhargav Kodali Date: Fri, 22 Nov 2024 21:15:36 -0700 Subject: [PATCH 3/3] correct typo --- .../esm-react-utils/src/openmrsComponentDecorator.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx b/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx index 14ef7a206..46b999dee 100644 --- a/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx +++ b/packages/framework/esm-react-utils/src/openmrsComponentDecorator.test.tsx @@ -36,7 +36,7 @@ describe('openmrs-component-decorator', () => { render(); }); - it("rendering a unsafe component is strict mode should log error in console",()=>{ + it("rendering a unsafe component in strict mode should log error in console",()=>{ const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {}); const UnsafeDecoratedCompnent = openmrsComponentDecorator(opts)(UnsafeComponent); render();