@openmrs/esm-react-utils 5.5.1-pre.1649 → 5.5.1-pre.1659
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 +15 -14
- package/dist/openmrs-esm-react-utils.js +1 -1
- package/dist/openmrs-esm-react-utils.js.map +1 -1
- package/jest.config.js +1 -2
- package/mock.tsx +94 -0
- package/package.json +10 -9
- package/__mocks__/openmrs-esm-state.mock.ts +0 -77
- package/__mocks__/openmrs-esm-styleguide.mock.tsx +0 -11
package/jest.config.js
CHANGED
|
@@ -6,8 +6,7 @@ module.exports = {
|
|
|
6
6
|
moduleNameMapper: {
|
|
7
7
|
'^lodash-es/(.*)$': 'lodash/$1',
|
|
8
8
|
'@openmrs/esm-error-handling': '<rootDir>/__mocks__/openmrs-esm-error-handling.mock.ts',
|
|
9
|
-
'@openmrs/esm-state': '
|
|
10
|
-
'@openmrs/esm-styleguide': '<rootDir>/__mocks__/openmrs-esm-styleguide.mock.tsx',
|
|
9
|
+
'@openmrs/esm-state': '@openmrs/esm-state/mock',
|
|
11
10
|
dexie: require.resolve('dexie'),
|
|
12
11
|
},
|
|
13
12
|
testEnvironment: 'jsdom',
|
package/mock.tsx
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { openmrsFetch } from '@openmrs/esm-api/mock';
|
|
3
|
+
import { configSchema } from '@openmrs/esm-config/mock';
|
|
4
|
+
import { getExtensionStore, getExtensionInternalStore } from '@openmrs/esm-extensions/mock';
|
|
5
|
+
import { createGlobalStore } from '@openmrs/esm-state/mock';
|
|
6
|
+
import { usePagination as realUsePagination } from './src/index';
|
|
7
|
+
export { ConfigurableLink, isDesktop, useStore, useStoreWithActions, createUseStore } from './src/index';
|
|
8
|
+
import * as utils from '@openmrs/esm-utils';
|
|
9
|
+
|
|
10
|
+
export const ComponentContext = React.createContext(null);
|
|
11
|
+
|
|
12
|
+
export const openmrsComponentDecorator = jest.fn().mockImplementation(() => (component) => component);
|
|
13
|
+
|
|
14
|
+
export const useAttachments = jest.fn(() => ({
|
|
15
|
+
isLoading: true,
|
|
16
|
+
data: [],
|
|
17
|
+
error: null,
|
|
18
|
+
mutate: jest.fn(),
|
|
19
|
+
isValidating: true,
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
export const useConfig = jest.fn().mockImplementation(() => utils.getDefaultsFromConfigSchema(configSchema));
|
|
23
|
+
|
|
24
|
+
export const useCurrentPatient = jest.fn(() => []);
|
|
25
|
+
|
|
26
|
+
export const usePatient = jest.fn(() => ({
|
|
27
|
+
isLoading: true,
|
|
28
|
+
patient: null,
|
|
29
|
+
patientUuid: null,
|
|
30
|
+
error: null,
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
export const useSession = jest.fn(() => ({
|
|
34
|
+
authenticated: false,
|
|
35
|
+
sessionId: '',
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
export const useLayoutType = jest.fn(() => 'desktop');
|
|
39
|
+
|
|
40
|
+
export const useAssignedExtensions = jest.fn(() => []);
|
|
41
|
+
|
|
42
|
+
export const useExtensionSlotMeta = jest.fn(() => ({}));
|
|
43
|
+
|
|
44
|
+
export const useConnectedExtensions = jest.fn(() => []);
|
|
45
|
+
|
|
46
|
+
export const UserHasAccess = jest.fn().mockImplementation((props: any) => {
|
|
47
|
+
return props.children;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const useExtensionInternalStore = createGlobalStore('extensionInternal', getExtensionInternalStore());
|
|
51
|
+
|
|
52
|
+
export const useExtensionStore = getExtensionStore();
|
|
53
|
+
|
|
54
|
+
export const ExtensionSlot = jest.fn().mockImplementation(({ children }) => <>{children}</>);
|
|
55
|
+
|
|
56
|
+
export const Extension = jest.fn().mockImplementation((props: any) => <slot />);
|
|
57
|
+
|
|
58
|
+
export const useFeatureFlag = jest.fn().mockReturnValue(true);
|
|
59
|
+
|
|
60
|
+
export const usePagination = jest.fn(realUsePagination);
|
|
61
|
+
|
|
62
|
+
export const useVisit = jest.fn().mockReturnValue({
|
|
63
|
+
error: null,
|
|
64
|
+
mutate: jest.fn(),
|
|
65
|
+
isValidating: true,
|
|
66
|
+
currentVisit: null,
|
|
67
|
+
activeVisit: null,
|
|
68
|
+
currentVisitIsRetrospective: false,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export const useVisitTypes = jest.fn(() => []);
|
|
72
|
+
|
|
73
|
+
export const useAbortController = jest.fn().mockReturnValue(() => {
|
|
74
|
+
let aborted = false;
|
|
75
|
+
return jest.fn(
|
|
76
|
+
() =>
|
|
77
|
+
({
|
|
78
|
+
abort: () => {
|
|
79
|
+
aborted = true;
|
|
80
|
+
},
|
|
81
|
+
signal: {
|
|
82
|
+
aborted,
|
|
83
|
+
},
|
|
84
|
+
}) as AbortController,
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const useOpenmrsSWR = jest.fn((key: string | Array<any>) => {
|
|
89
|
+
return { data: openmrsFetch(key.toString()) };
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const useDebounce = jest.fn().mockImplementation((value) => value);
|
|
93
|
+
|
|
94
|
+
export const useOnClickOutside = jest.fn();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-react-utils",
|
|
3
|
-
"version": "5.5.1-pre.
|
|
3
|
+
"version": "5.5.1-pre.1659",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "React utilities for OpenMRS.",
|
|
6
6
|
"browser": "dist/openmrs-esm-react-utils.js",
|
|
@@ -47,10 +47,11 @@
|
|
|
47
47
|
"@openmrs/esm-config": "5.x",
|
|
48
48
|
"@openmrs/esm-error-handling": "5.x",
|
|
49
49
|
"@openmrs/esm-extensions": "5.x",
|
|
50
|
+
"@openmrs/esm-feature-flags": "5.x",
|
|
50
51
|
"@openmrs/esm-globals": "5.x",
|
|
51
52
|
"@openmrs/esm-navigation": "5.x",
|
|
52
53
|
"dayjs": "1.x",
|
|
53
|
-
"i18next": "
|
|
54
|
+
"i18next": "21.x",
|
|
54
55
|
"react": "18.x",
|
|
55
56
|
"react-dom": "18.x",
|
|
56
57
|
"react-i18next": "11.x",
|
|
@@ -58,13 +59,13 @@
|
|
|
58
59
|
"swr": "2.x"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"@openmrs/esm-api": "5.5.1-pre.
|
|
62
|
-
"@openmrs/esm-config": "5.5.1-pre.
|
|
63
|
-
"@openmrs/esm-error-handling": "5.5.1-pre.
|
|
64
|
-
"@openmrs/esm-extensions": "5.5.1-pre.
|
|
65
|
-
"@openmrs/esm-feature-flags": "5.5.1-pre.
|
|
66
|
-
"@openmrs/esm-globals": "5.5.1-pre.
|
|
67
|
-
"@openmrs/esm-navigation": "5.5.1-pre.
|
|
62
|
+
"@openmrs/esm-api": "5.5.1-pre.1659",
|
|
63
|
+
"@openmrs/esm-config": "5.5.1-pre.1659",
|
|
64
|
+
"@openmrs/esm-error-handling": "5.5.1-pre.1659",
|
|
65
|
+
"@openmrs/esm-extensions": "5.5.1-pre.1659",
|
|
66
|
+
"@openmrs/esm-feature-flags": "5.5.1-pre.1659",
|
|
67
|
+
"@openmrs/esm-globals": "5.5.1-pre.1659",
|
|
68
|
+
"@openmrs/esm-navigation": "5.5.1-pre.1659",
|
|
68
69
|
"dayjs": "^1.10.8",
|
|
69
70
|
"i18next": "^21.10.0",
|
|
70
71
|
"react": "^18.1.0",
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { createStore, StoreApi } from 'zustand';
|
|
2
|
-
|
|
3
|
-
interface StoreEntity {
|
|
4
|
-
value: StoreApi<any>;
|
|
5
|
-
active: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type MockedStore<T> = StoreApi<T> & { resetMock: () => void };
|
|
9
|
-
|
|
10
|
-
const initialStates: Record<string, any> = {};
|
|
11
|
-
|
|
12
|
-
const availableStores: Record<string, StoreEntity> = {};
|
|
13
|
-
|
|
14
|
-
export const mockStores = availableStores;
|
|
15
|
-
|
|
16
|
-
export function createGlobalStore<T>(name: string, initialState: T): StoreApi<T> {
|
|
17
|
-
const available = availableStores[name];
|
|
18
|
-
|
|
19
|
-
if (available) {
|
|
20
|
-
if (available.active) {
|
|
21
|
-
console.error('Cannot override an existing store. Make sure that stores are only created once.');
|
|
22
|
-
} else {
|
|
23
|
-
available.value.setState(initialState, true);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
available.active = true;
|
|
27
|
-
return available.value;
|
|
28
|
-
} else {
|
|
29
|
-
const store = createStore<T>()(() => initialState);
|
|
30
|
-
initialStates[name] = initialState;
|
|
31
|
-
|
|
32
|
-
availableStores[name] = {
|
|
33
|
-
value: store,
|
|
34
|
-
active: true,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return instrumentedStore(name, store);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function getGlobalStore<T>(name: string, fallbackState?: T): StoreApi<T> {
|
|
42
|
-
const available = availableStores[name];
|
|
43
|
-
|
|
44
|
-
if (!available) {
|
|
45
|
-
const store = createStore<T>()(() => fallbackState ?? ({} as unknown as T));
|
|
46
|
-
initialStates[name] = fallbackState;
|
|
47
|
-
availableStores[name] = {
|
|
48
|
-
value: store,
|
|
49
|
-
active: false,
|
|
50
|
-
};
|
|
51
|
-
return instrumentedStore(name, store);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return instrumentedStore(name, available.value);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function subscribeTo<T, U>(store: StoreApi<T>, select: (state: T) => U, handle: (subState: U) => void) {
|
|
58
|
-
let previous = select(store.getState());
|
|
59
|
-
|
|
60
|
-
return store.subscribe((state) => {
|
|
61
|
-
const current = select(state);
|
|
62
|
-
|
|
63
|
-
if (current !== previous) {
|
|
64
|
-
previous = current;
|
|
65
|
-
handle(current);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function instrumentedStore<T>(name: string, store: StoreApi<T>) {
|
|
71
|
-
return {
|
|
72
|
-
getState: jest.spyOn(store, 'getState'),
|
|
73
|
-
setState: jest.spyOn(store, 'setState'),
|
|
74
|
-
subscribe: jest.spyOn(store, 'subscribe'),
|
|
75
|
-
resetMock: () => store.setState(initialStates[name]),
|
|
76
|
-
} as any as MockedStore<T>;
|
|
77
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const showNotification = jest.fn();
|
|
2
|
-
export const showActionableNotification = jest.fn();
|
|
3
|
-
export const showSnackbar = jest.fn();
|
|
4
|
-
export const showToast = jest.fn();
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
showNotification.mockReset();
|
|
8
|
-
showActionableNotification.mockReset();
|
|
9
|
-
showToast.mockReset();
|
|
10
|
-
showSnackbar.mockReset();
|
|
11
|
-
});
|