@openmrs/esm-react-utils 5.3.3-pre.1286 → 5.3.3-pre.1296

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- @openmrs/esm-react-utils:build: cache hit, replaying output cbe98f5f1428847f
1
+ @openmrs/esm-react-utils:build: cache hit, replaying output ed5b158184da45aa
2
2
  @openmrs/esm-react-utils:build: Browserslist: caniuse-lite is outdated. Please run:
3
3
  @openmrs/esm-react-utils:build:  npx update-browserslist-db@latest
4
4
  @openmrs/esm-react-utils:build:  Why you should do it regularly: https://github.com/browserslist/update-db#readme
@@ -14,4 +14,4 @@
14
14
  @openmrs/esm-react-utils:build:  external "@openmrs/esm-extensions" 42 bytes [built] [code generated]
15
15
  @openmrs/esm-react-utils:build:  + 2 modules
16
16
  @openmrs/esm-react-utils:build:  + 5 modules
17
- @openmrs/esm-react-utils:build: webpack 5.88.0 compiled successfully in 4633 ms
17
+ @openmrs/esm-react-utils:build: webpack 5.88.0 compiled successfully in 4557 ms
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-react-utils",
3
- "version": "5.3.3-pre.1286",
3
+ "version": "5.3.3-pre.1296",
4
4
  "license": "MPL-2.0",
5
5
  "description": "React utilities for OpenMRS.",
6
6
  "browser": "dist/openmrs-esm-react-utils.js",
@@ -57,12 +57,12 @@
57
57
  "swr": "2.x"
58
58
  },
59
59
  "devDependencies": {
60
- "@openmrs/esm-api": "5.3.3-pre.1286",
61
- "@openmrs/esm-config": "5.3.3-pre.1286",
62
- "@openmrs/esm-error-handling": "5.3.3-pre.1286",
63
- "@openmrs/esm-extensions": "5.3.3-pre.1286",
64
- "@openmrs/esm-feature-flags": "5.3.3-pre.1286",
65
- "@openmrs/esm-globals": "5.3.3-pre.1286",
60
+ "@openmrs/esm-api": "5.3.3-pre.1296",
61
+ "@openmrs/esm-config": "5.3.3-pre.1296",
62
+ "@openmrs/esm-error-handling": "5.3.3-pre.1296",
63
+ "@openmrs/esm-extensions": "5.3.3-pre.1296",
64
+ "@openmrs/esm-feature-flags": "5.3.3-pre.1296",
65
+ "@openmrs/esm-globals": "5.3.3-pre.1296",
66
66
  "dayjs": "^1.10.8",
67
67
  "i18next": "^21.10.0",
68
68
  "react": "^18.1.0",
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import '@testing-library/jest-dom/extend-expect';
2
+ import '@testing-library/jest-dom';
3
3
  import { render, screen } from '@testing-library/react';
4
4
  import userEvent from '@testing-library/user-event';
5
5
  import { navigate, interpolateUrl } from '@openmrs/esm-config';
@@ -28,6 +28,10 @@ describe('ExtensionSlot, Extension, and useExtensionSlotMeta', () => {
28
28
  updateInternalExtensionStore(() => ({ slots: {}, extensions: {} }));
29
29
  });
30
30
 
31
+ afterEach(() => {
32
+ jest.clearAllMocks();
33
+ });
34
+
31
35
  test('Extension receives state changes passed through (not using <Extension>)', async () => {
32
36
  function EnglishExtension({ suffix }) {
33
37
  return <div>English{suffix}</div>;
@@ -87,16 +91,22 @@ describe('ExtensionSlot, Extension, and useExtensionSlotMeta', () => {
87
91
  });
88
92
 
89
93
  test('ExtensionSlot throws error if both state and children provided', () => {
94
+ const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
90
95
  const App = () => (
91
96
  <ExtensionSlot name="Box" state={{ color: 'red' }}>
92
97
  <Extension />
93
98
  </ExtensionSlot>
94
99
  );
95
- expect(() => render(<App />)).toThrowError(
100
+ expect(() => render(<App />)).toThrow();
101
+ expect(consoleError).toHaveBeenNthCalledWith(
102
+ 1,
96
103
  expect.objectContaining({
97
- message: expect.stringMatching(/children.*state/),
104
+ message: expect.stringMatching(
105
+ /Both children and state have been provided. If children are provided, the state must be passed as a prop to the `Extension` component/i,
106
+ ),
98
107
  }),
99
108
  );
109
+ consoleError.mockRestore();
100
110
  });
101
111
 
102
112
  test('Extension Slot receives meta', async () => {
@@ -111,10 +121,10 @@ describe('ExtensionSlot, Extension, and useExtensionSlotMeta', () => {
111
121
  })(() => {
112
122
  const metas = useExtensionSlotMeta('Box');
113
123
  const wrapItem = useCallback(
114
- (slot: React.ReactNode, extension: ExtensionData) => {
124
+ (slot: React.ReactNode, extension?: ExtensionData) => {
115
125
  return (
116
126
  <div>
117
- <h1>{metas[getExtensionNameFromId(extension.extensionId)].code}</h1>
127
+ <h1>{metas[getExtensionNameFromId(extension?.extensionId ?? '')].code}</h1>
118
128
  {slot}
119
129
  </div>
120
130
  );
@@ -124,7 +134,7 @@ describe('ExtensionSlot, Extension, and useExtensionSlotMeta', () => {
124
134
  return (
125
135
  <div>
126
136
  <ExtensionSlot name="Box">
127
- <Extension wrap={wrapItem} />
137
+ <Extension>{wrapItem}</Extension>
128
138
  </ExtensionSlot>
129
139
  </div>
130
140
  );
@@ -13,15 +13,22 @@ describe('openmrs-component-decorator', () => {
13
13
  it('renders a component', () => {
14
14
  const DecoratedComp = openmrsComponentDecorator(opts)(CompThatWorks);
15
15
  render(<DecoratedComp />);
16
- waitFor(() => {
17
- expect(screen.getByText('The button')).toBeTruthy();
18
- });
16
+
17
+ screen.findByText('The button');
19
18
  });
20
19
 
21
20
  it('catches any errors in the component tree and renders a ui explaining something bad happened', () => {
21
+ const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});
22
22
  const DecoratedComp = openmrsComponentDecorator(opts)(CompThatThrows);
23
23
  render(<DecoratedComp />);
24
24
  // TO-DO assert the UX for broken react app is showing
25
+ expect(consoleError).toHaveBeenNthCalledWith(
26
+ 1,
27
+ expect.objectContaining({
28
+ message: expect.stringContaining('ahahaa'),
29
+ }),
30
+ );
31
+ consoleError.mockRestore();
25
32
  });
26
33
 
27
34
  it('provides ComponentContext', () => {
@@ -1,4 +1,4 @@
1
- import '@testing-library/jest-dom/extend-expect';
1
+ import '@testing-library/jest-dom';
2
2
 
3
3
  window.openmrsBase = '/openmrs';
4
4
  window.spaBase = '/spa';
@@ -1,5 +1,5 @@
1
1
  import { renderHook, cleanup } from '@testing-library/react';
2
- import '@testing-library/jest-dom/extend-expect';
2
+ import '@testing-library/jest-dom';
3
3
  import useAbortController from './useAbortController';
4
4
 
5
5
  describe('useAbortController', () => {
@@ -1,12 +1,14 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
- import { render, fireEvent } from '@testing-library/react';
2
+ import { render } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
3
4
  import { useOnClickOutside } from './useOnClickOutside';
4
5
 
5
6
  describe('useOnClickOutside', () => {
6
7
  const handler: (e: Event) => void = jest.fn();
7
8
  afterEach(() => (handler as jest.Mock).mockClear());
8
9
 
9
- it('should call the handler when clicking outside', () => {
10
+ it('should call the handler when clicking outside', async () => {
11
+ const user = userEvent.setup();
10
12
  // setup
11
13
  const Component: React.FC<PropsWithChildren> = ({ children }) => {
12
14
  const ref = useOnClickOutside<HTMLDivElement>(handler);
@@ -15,14 +17,15 @@ describe('useOnClickOutside', () => {
15
17
  const ref = render(<Component />);
16
18
 
17
19
  // act
18
- fireEvent.click(ref.container);
20
+ await user.click(ref.container);
19
21
 
20
22
  // verify
21
23
  expect(handler).toHaveBeenCalledTimes(1);
22
24
  });
23
25
 
24
- it('should not call the handler when clicking on the element', () => {
26
+ it('should not call the handler when clicking on the element', async () => {
25
27
  // setup
28
+ const user = userEvent.setup();
26
29
  const Component: React.FC<PropsWithChildren> = ({ children }) => {
27
30
  const ref = useOnClickOutside<HTMLDivElement>(handler);
28
31
  return <div ref={ref}>{children}</div>;
@@ -36,7 +39,7 @@ describe('useOnClickOutside', () => {
36
39
 
37
40
  // act
38
41
  if (mutableRef.current) {
39
- fireEvent.click(mutableRef.current);
42
+ await user.click(mutableRef.current);
40
43
  }
41
44
 
42
45
  // verify