@openmrs/esm-react-utils 5.3.3-pre.1291 → 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.
- package/.turbo/turbo-build.log +2 -2
- package/package.json +7 -7
- package/src/ConfigurableLink.test.tsx +1 -1
- package/src/extensions.test.tsx +15 -5
- package/src/openmrsComponentDecorator.test.tsx +10 -3
- package/src/setup-tests.js +1 -1
- package/src/useAbortController.test.tsx +1 -1
- package/src/useOnClickOutside.test.tsx +8 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[33m@openmrs/esm-react-utils:build[0m: cache hit, replaying output [
|
|
1
|
+
[33m@openmrs/esm-react-utils:build[0m: cache hit, replaying output [2med5b158184da45aa[0m
|
|
2
2
|
[33m@openmrs/esm-react-utils:build: [0mBrowserslist: caniuse-lite is outdated. Please run:
|
|
3
3
|
[33m@openmrs/esm-react-utils:build: [0m npx update-browserslist-db@latest
|
|
4
4
|
[33m@openmrs/esm-react-utils:build: [0m Why you should do it regularly: https://github.com/browserslist/update-db#readme
|
|
@@ -14,4 +14,4 @@
|
|
|
14
14
|
[33m@openmrs/esm-react-utils:build: [0m [1mexternal "@openmrs/esm-extensions"[39m[22m 42 bytes [1m[33m[built][39m[22m [1m[33m[code generated][39m[22m
|
|
15
15
|
[33m@openmrs/esm-react-utils:build: [0m + 2 modules
|
|
16
16
|
[33m@openmrs/esm-react-utils:build: [0m + 5 modules
|
|
17
|
-
[33m@openmrs/esm-react-utils:build: [0mwebpack 5.88.0 compiled [1m[32msuccessfully[39m[22m in
|
|
17
|
+
[33m@openmrs/esm-react-utils:build: [0mwebpack 5.88.0 compiled [1m[32msuccessfully[39m[22m 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.
|
|
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.
|
|
61
|
-
"@openmrs/esm-config": "5.3.3-pre.
|
|
62
|
-
"@openmrs/esm-error-handling": "5.3.3-pre.
|
|
63
|
-
"@openmrs/esm-extensions": "5.3.3-pre.
|
|
64
|
-
"@openmrs/esm-feature-flags": "5.3.3-pre.
|
|
65
|
-
"@openmrs/esm-globals": "5.3.3-pre.
|
|
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
|
|
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';
|
package/src/extensions.test.tsx
CHANGED
|
@@ -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 />)).
|
|
100
|
+
expect(() => render(<App />)).toThrow();
|
|
101
|
+
expect(consoleError).toHaveBeenNthCalledWith(
|
|
102
|
+
1,
|
|
96
103
|
expect.objectContaining({
|
|
97
|
-
message: expect.stringMatching(
|
|
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
|
|
124
|
+
(slot: React.ReactNode, extension?: ExtensionData) => {
|
|
115
125
|
return (
|
|
116
126
|
<div>
|
|
117
|
-
<h1>{metas[getExtensionNameFromId(extension
|
|
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
|
|
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
|
-
|
|
17
|
-
|
|
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', () => {
|
package/src/setup-tests.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { render
|
|
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
|
-
|
|
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
|
-
|
|
42
|
+
await user.click(mutableRef.current);
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
// verify
|