@openmrs/esm-framework 3.1.10-pre.92 → 3.1.11-pre.597

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.
Files changed (105) hide show
  1. package/README.md +2 -8
  2. package/dist/openmrs-esm-framework.js +2 -21
  3. package/dist/openmrs-esm-framework.js.LICENSE.txt +16 -0
  4. package/dist/openmrs-esm-framework.js.map +1 -1
  5. package/docs/API.md +4381 -0
  6. package/docs/classes/OpenmrsFetchError.md +186 -0
  7. package/docs/enums/Type.md +85 -0
  8. package/docs/enums/VisitMode.md +41 -0
  9. package/docs/enums/VisitStatus.md +30 -0
  10. package/docs/interfaces/AppState.md +3 -0
  11. package/docs/interfaces/BreadcrumbRegistration.md +30 -0
  12. package/docs/interfaces/BreadcrumbSettings.md +70 -0
  13. package/docs/interfaces/CancelLoading.md +17 -0
  14. package/docs/interfaces/ClearDynamicRoutesMessage.md +29 -0
  15. package/docs/interfaces/ComponentConfig.md +30 -0
  16. package/docs/interfaces/ComponentDecoratorOptions.md +52 -0
  17. package/docs/interfaces/ComponentDefinition.md +101 -0
  18. package/docs/interfaces/Config.md +182 -0
  19. package/docs/interfaces/ConfigObject.md +182 -0
  20. package/docs/interfaces/ConfigSchema.md +45 -0
  21. package/docs/interfaces/ConfigStore.md +34 -0
  22. package/docs/interfaces/ConfigurableLinkProps.md +25 -0
  23. package/docs/interfaces/ConnectivityChangedEvent.md +19 -0
  24. package/docs/interfaces/CurrentPatientOptions.md +27 -0
  25. package/docs/interfaces/CurrentUserOptions.md +27 -0
  26. package/docs/interfaces/CurrentUserWithResponseOption.md +29 -0
  27. package/docs/interfaces/CurrentUserWithoutResponseOption.md +29 -0
  28. package/docs/interfaces/ExtensionComponentDefinition.md +153 -0
  29. package/docs/interfaces/ExtensionData.md +41 -0
  30. package/docs/interfaces/ExtensionDetails.md +81 -0
  31. package/docs/interfaces/ExtensionInfo.md +140 -0
  32. package/docs/interfaces/ExtensionInstance.md +19 -0
  33. package/docs/interfaces/ExtensionMeta.md +7 -0
  34. package/docs/interfaces/ExtensionProps.md +44 -0
  35. package/docs/interfaces/ExtensionRegistration.md +98 -0
  36. package/docs/interfaces/ExtensionSlotBaseProps.md +54 -0
  37. package/docs/interfaces/ExtensionSlotConfig.md +52 -0
  38. package/docs/interfaces/ExtensionSlotConfigObject.md +41 -0
  39. package/docs/interfaces/ExtensionSlotConfigsStore.md +32 -0
  40. package/docs/interfaces/ExtensionSlotConfigureValueObject.md +7 -0
  41. package/docs/interfaces/ExtensionSlotInfo.md +50 -0
  42. package/docs/interfaces/ExtensionSlotInstance.md +51 -0
  43. package/docs/interfaces/ExtensionStore.md +34 -0
  44. package/docs/interfaces/FHIRCode.md +30 -0
  45. package/docs/interfaces/FHIRRequestObj.md +41 -0
  46. package/docs/interfaces/FHIRResource.md +46 -0
  47. package/docs/interfaces/FetchHeaders.md +7 -0
  48. package/docs/interfaces/FetchResponse.md +285 -0
  49. package/docs/interfaces/ImplementerToolsConfigStore.md +19 -0
  50. package/docs/interfaces/ImportMap.md +19 -0
  51. package/docs/interfaces/LegacyAppExtensionDefinition.md +170 -0
  52. package/docs/interfaces/Lifecycle.md +68 -0
  53. package/docs/interfaces/Location.md +41 -0
  54. package/docs/interfaces/LoggedInUser.md +133 -0
  55. package/docs/interfaces/LoggedInUserFetchResponse.md +281 -0
  56. package/docs/interfaces/MessageServiceWorkerResult.md +47 -0
  57. package/docs/interfaces/ModernAppExtensionDefinition.md +196 -0
  58. package/docs/interfaces/NavigateOptions.md +19 -0
  59. package/docs/interfaces/NavigationContext.md +50 -0
  60. package/docs/interfaces/NetworkRequestFailedEvent.md +49 -0
  61. package/docs/interfaces/NewVisitPayload.md +74 -0
  62. package/docs/interfaces/OfflinePatientArgs.md +34 -0
  63. package/docs/interfaces/OfflinePatientDataSyncHandler.md +52 -0
  64. package/docs/interfaces/OfflinePatientDataSyncState.md +99 -0
  65. package/docs/interfaces/OfflinePatientDataSyncStore.md +37 -0
  66. package/docs/interfaces/OfflineSynchronizationStore.md +27 -0
  67. package/docs/interfaces/OmrsServiceWorkerEvent.md +31 -0
  68. package/docs/interfaces/OmrsServiceWorkerMessage.md +35 -0
  69. package/docs/interfaces/OnImportMapChangedMessage.md +40 -0
  70. package/docs/interfaces/OnlyThePatient.md +29 -0
  71. package/docs/interfaces/OpenmrsReactComponentProps.md +19 -0
  72. package/docs/interfaces/OpenmrsReactComponentState.md +41 -0
  73. package/docs/interfaces/OpenmrsResource.md +34 -0
  74. package/docs/interfaces/PageDefinition.md +149 -0
  75. package/docs/interfaces/PatientWithFullResponse.md +29 -0
  76. package/docs/interfaces/Person.md +41 -0
  77. package/docs/interfaces/PrecacheStaticDependenciesEvent.md +3 -0
  78. package/docs/interfaces/Privilege.md +41 -0
  79. package/docs/interfaces/QueueItemDescriptor.md +52 -0
  80. package/docs/interfaces/RegisterDynamicRouteMessage.md +51 -0
  81. package/docs/interfaces/ResourceLoader.md +23 -0
  82. package/docs/interfaces/RetryOptions.md +83 -0
  83. package/docs/interfaces/Role.md +41 -0
  84. package/docs/interfaces/SessionLocation.md +41 -0
  85. package/docs/interfaces/SessionUser.md +92 -0
  86. package/docs/interfaces/ShowNotificationEvent.md +63 -0
  87. package/docs/interfaces/ShowToastEvent.md +52 -0
  88. package/docs/interfaces/SpaConfig.md +77 -0
  89. package/docs/interfaces/SyncItem.md +92 -0
  90. package/docs/interfaces/SyncProcessOptions.md +69 -0
  91. package/docs/interfaces/UnauthenticatedUser.md +52 -0
  92. package/docs/interfaces/User.md +107 -0
  93. package/docs/interfaces/UserHasAccessProps.md +19 -0
  94. package/docs/interfaces/Visit.md +111 -0
  95. package/docs/interfaces/VisitItem.md +52 -0
  96. package/docs/interfaces/VisitType.md +41 -0
  97. package/docs/interfaces/WorkspaceItem.md +74 -0
  98. package/mock.tsx +253 -0
  99. package/package.json +15 -12
  100. package/src/index.ts +3 -1
  101. package/tsconfig.json +1 -0
  102. package/typedoc.json +7 -0
  103. package/webpack.config.js +4 -10
  104. package/src/set-public-path.ts +0 -3
  105. package/src/types.ts +0 -19
@@ -0,0 +1,107 @@
1
+ [@openmrs/esm-framework](../API.md) / User
2
+
3
+ # Interface: User
4
+
5
+ ## Table of contents
6
+
7
+ ### Properties
8
+
9
+ - [display](User.md#display)
10
+ - [link](User.md#link)
11
+ - [persion](User.md#persion)
12
+ - [priviliges](User.md#priviliges)
13
+ - [resourceVersion](User.md#resourceversion)
14
+ - [roles](User.md#roles)
15
+ - [userProperties](User.md#userproperties)
16
+ - [username](User.md#username)
17
+ - [uuid](User.md#uuid)
18
+
19
+ ## Properties
20
+
21
+ ### display
22
+
23
+ • **display**: `string`
24
+
25
+ #### Defined in
26
+
27
+ [packages/framework/esm-api/src/types/openmrs-resource.ts:18](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/openmrs-resource.ts#L18)
28
+
29
+ ___
30
+
31
+ ### link
32
+
33
+ • **link**: `string`[]
34
+
35
+ #### Defined in
36
+
37
+ [packages/framework/esm-api/src/types/openmrs-resource.ts:19](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/openmrs-resource.ts#L19)
38
+
39
+ ___
40
+
41
+ ### persion
42
+
43
+ • **persion**: `any`
44
+
45
+ #### Defined in
46
+
47
+ [packages/framework/esm-api/src/types/openmrs-resource.ts:20](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/openmrs-resource.ts#L20)
48
+
49
+ ___
50
+
51
+ ### priviliges
52
+
53
+ • **priviliges**: `any`
54
+
55
+ #### Defined in
56
+
57
+ [packages/framework/esm-api/src/types/openmrs-resource.ts:21](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/openmrs-resource.ts#L21)
58
+
59
+ ___
60
+
61
+ ### resourceVersion
62
+
63
+ • **resourceVersion**: `any`
64
+
65
+ #### Defined in
66
+
67
+ [packages/framework/esm-api/src/types/openmrs-resource.ts:22](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/openmrs-resource.ts#L22)
68
+
69
+ ___
70
+
71
+ ### roles
72
+
73
+ • **roles**: `any`[]
74
+
75
+ #### Defined in
76
+
77
+ [packages/framework/esm-api/src/types/openmrs-resource.ts:23](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/openmrs-resource.ts#L23)
78
+
79
+ ___
80
+
81
+ ### userProperties
82
+
83
+ • **userProperties**: `any`
84
+
85
+ #### Defined in
86
+
87
+ [packages/framework/esm-api/src/types/openmrs-resource.ts:24](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/openmrs-resource.ts#L24)
88
+
89
+ ___
90
+
91
+ ### username
92
+
93
+ • **username**: `string`
94
+
95
+ #### Defined in
96
+
97
+ [packages/framework/esm-api/src/types/openmrs-resource.ts:25](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/openmrs-resource.ts#L25)
98
+
99
+ ___
100
+
101
+ ### uuid
102
+
103
+ • **uuid**: `string`
104
+
105
+ #### Defined in
106
+
107
+ [packages/framework/esm-api/src/types/openmrs-resource.ts:26](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/openmrs-resource.ts#L26)
@@ -0,0 +1,19 @@
1
+ [@openmrs/esm-framework](../API.md) / UserHasAccessProps
2
+
3
+ # Interface: UserHasAccessProps
4
+
5
+ ## Table of contents
6
+
7
+ ### Properties
8
+
9
+ - [privilege](UserHasAccessProps.md#privilege)
10
+
11
+ ## Properties
12
+
13
+ ### privilege
14
+
15
+ • **privilege**: `string`
16
+
17
+ #### Defined in
18
+
19
+ [packages/framework/esm-react-utils/src/UserHasAccess.tsx:5](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-react-utils/src/UserHasAccess.tsx#L5)
@@ -0,0 +1,111 @@
1
+ [@openmrs/esm-framework](../API.md) / Visit
2
+
3
+ # Interface: Visit
4
+
5
+ ## Indexable
6
+
7
+ ▪ [anythingElse: `string`]: `any`
8
+
9
+ ## Table of contents
10
+
11
+ ### Properties
12
+
13
+ - [attributes](Visit.md#attributes)
14
+ - [display](Visit.md#display)
15
+ - [encounters](Visit.md#encounters)
16
+ - [location](Visit.md#location)
17
+ - [patient](Visit.md#patient)
18
+ - [startDatetime](Visit.md#startdatetime)
19
+ - [stopDatetime](Visit.md#stopdatetime)
20
+ - [uuid](Visit.md#uuid)
21
+ - [visitType](Visit.md#visittype)
22
+
23
+ ## Properties
24
+
25
+ ### attributes
26
+
27
+ • `Optional` **attributes**: [`OpenmrsResource`](OpenmrsResource.md)[]
28
+
29
+ #### Defined in
30
+
31
+ [packages/framework/esm-api/src/types/visit-resource.ts:23](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L23)
32
+
33
+ ___
34
+
35
+ ### display
36
+
37
+ • `Optional` **display**: `string`
38
+
39
+ #### Defined in
40
+
41
+ [packages/framework/esm-api/src/types/visit-resource.ts:16](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L16)
42
+
43
+ ___
44
+
45
+ ### encounters
46
+
47
+ • **encounters**: [`OpenmrsResource`](OpenmrsResource.md)[]
48
+
49
+ #### Defined in
50
+
51
+ [packages/framework/esm-api/src/types/visit-resource.ts:17](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L17)
52
+
53
+ ___
54
+
55
+ ### location
56
+
57
+ • `Optional` **location**: [`Location`](Location.md)
58
+
59
+ #### Defined in
60
+
61
+ [packages/framework/esm-api/src/types/visit-resource.ts:20](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L20)
62
+
63
+ ___
64
+
65
+ ### patient
66
+
67
+ • `Optional` **patient**: [`OpenmrsResource`](OpenmrsResource.md)
68
+
69
+ #### Defined in
70
+
71
+ [packages/framework/esm-api/src/types/visit-resource.ts:18](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L18)
72
+
73
+ ___
74
+
75
+ ### startDatetime
76
+
77
+ • **startDatetime**: `Date`
78
+
79
+ #### Defined in
80
+
81
+ [packages/framework/esm-api/src/types/visit-resource.ts:21](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L21)
82
+
83
+ ___
84
+
85
+ ### stopDatetime
86
+
87
+ • `Optional` **stopDatetime**: `Date`
88
+
89
+ #### Defined in
90
+
91
+ [packages/framework/esm-api/src/types/visit-resource.ts:22](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L22)
92
+
93
+ ___
94
+
95
+ ### uuid
96
+
97
+ • **uuid**: `string`
98
+
99
+ #### Defined in
100
+
101
+ [packages/framework/esm-api/src/types/visit-resource.ts:15](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L15)
102
+
103
+ ___
104
+
105
+ ### visitType
106
+
107
+ • **visitType**: [`VisitType`](VisitType.md)
108
+
109
+ #### Defined in
110
+
111
+ [packages/framework/esm-api/src/types/visit-resource.ts:19](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L19)
@@ -0,0 +1,52 @@
1
+ [@openmrs/esm-framework](../API.md) / VisitItem
2
+
3
+ # Interface: VisitItem
4
+
5
+ ## Table of contents
6
+
7
+ ### Properties
8
+
9
+ - [anythingElse](VisitItem.md#anythingelse)
10
+ - [mode](VisitItem.md#mode)
11
+ - [status](VisitItem.md#status)
12
+ - [visitData](VisitItem.md#visitdata)
13
+
14
+ ## Properties
15
+
16
+ ### anythingElse
17
+
18
+ • `Optional` **anythingElse**: `any`
19
+
20
+ #### Defined in
21
+
22
+ [packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:90](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L90)
23
+
24
+ ___
25
+
26
+ ### mode
27
+
28
+ • **mode**: [`VisitMode`](../enums/VisitMode.md)
29
+
30
+ #### Defined in
31
+
32
+ [packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:87](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L87)
33
+
34
+ ___
35
+
36
+ ### status
37
+
38
+ • **status**: [`VisitStatus`](../enums/VisitStatus.md)
39
+
40
+ #### Defined in
41
+
42
+ [packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:89](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L89)
43
+
44
+ ___
45
+
46
+ ### visitData
47
+
48
+ • `Optional` **visitData**: [`Visit`](Visit.md)
49
+
50
+ #### Defined in
51
+
52
+ [packages/framework/esm-api/src/shared-api-objects/visit-utils.ts:88](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/shared-api-objects/visit-utils.ts#L88)
@@ -0,0 +1,41 @@
1
+ [@openmrs/esm-framework](../API.md) / VisitType
2
+
3
+ # Interface: VisitType
4
+
5
+ ## Table of contents
6
+
7
+ ### Properties
8
+
9
+ - [display](VisitType.md#display)
10
+ - [name](VisitType.md#name)
11
+ - [uuid](VisitType.md#uuid)
12
+
13
+ ## Properties
14
+
15
+ ### display
16
+
17
+ • **display**: `string`
18
+
19
+ #### Defined in
20
+
21
+ [packages/framework/esm-api/src/types/visit-resource.ts:35](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L35)
22
+
23
+ ___
24
+
25
+ ### name
26
+
27
+ • `Optional` **name**: `string`
28
+
29
+ #### Defined in
30
+
31
+ [packages/framework/esm-api/src/types/visit-resource.ts:36](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L36)
32
+
33
+ ___
34
+
35
+ ### uuid
36
+
37
+ • **uuid**: `string`
38
+
39
+ #### Defined in
40
+
41
+ [packages/framework/esm-api/src/types/visit-resource.ts:34](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/types/visit-resource.ts#L34)
@@ -0,0 +1,74 @@
1
+ [@openmrs/esm-framework](../API.md) / WorkspaceItem
2
+
3
+ # Interface: WorkspaceItem
4
+
5
+ ## Table of contents
6
+
7
+ ### Properties
8
+
9
+ - [component](WorkspaceItem.md#component)
10
+ - [componentClosed](WorkspaceItem.md#componentclosed)
11
+ - [inProgress](WorkspaceItem.md#inprogress)
12
+ - [name](WorkspaceItem.md#name)
13
+ - [props](WorkspaceItem.md#props)
14
+ - [validations](WorkspaceItem.md#validations)
15
+
16
+ ## Properties
17
+
18
+ ### component
19
+
20
+ • **component**: `any`
21
+
22
+ #### Defined in
23
+
24
+ [packages/framework/esm-api/src/workspace/workspace.resource.tsx:24](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/workspace/workspace.resource.tsx#L24)
25
+
26
+ ___
27
+
28
+ ### componentClosed
29
+
30
+ • `Optional` **componentClosed**: `Function`
31
+
32
+ #### Defined in
33
+
34
+ [packages/framework/esm-api/src/workspace/workspace.resource.tsx:29](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/workspace/workspace.resource.tsx#L29)
35
+
36
+ ___
37
+
38
+ ### inProgress
39
+
40
+ • **inProgress**: `boolean`
41
+
42
+ #### Defined in
43
+
44
+ [packages/framework/esm-api/src/workspace/workspace.resource.tsx:28](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/workspace/workspace.resource.tsx#L28)
45
+
46
+ ___
47
+
48
+ ### name
49
+
50
+ • **name**: `string`
51
+
52
+ #### Defined in
53
+
54
+ [packages/framework/esm-api/src/workspace/workspace.resource.tsx:25](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/workspace/workspace.resource.tsx#L25)
55
+
56
+ ___
57
+
58
+ ### props
59
+
60
+ • **props**: `any`
61
+
62
+ #### Defined in
63
+
64
+ [packages/framework/esm-api/src/workspace/workspace.resource.tsx:26](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/workspace/workspace.resource.tsx#L26)
65
+
66
+ ___
67
+
68
+ ### validations
69
+
70
+ • `Optional` **validations**: `Function`
71
+
72
+ #### Defined in
73
+
74
+ [packages/framework/esm-api/src/workspace/workspace.resource.tsx:27](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-api/src/workspace/workspace.resource.tsx#L27)
package/mock.tsx ADDED
@@ -0,0 +1,253 @@
1
+ import React from "react";
2
+ import type {} from "@openmrs/esm-globals";
3
+ import createStore, { Store } from "unistore";
4
+ import { never, of } from "rxjs";
5
+
6
+ interface StoreEntity {
7
+ value: Store<any>;
8
+ active: boolean;
9
+ }
10
+
11
+ export type MockedStore<T> = Store<T> & { resetMock: () => void };
12
+
13
+ const initialStates: Record<string, any> = {};
14
+
15
+ const availableStores: Record<string, StoreEntity> = {};
16
+
17
+ export function isVersionSatisfied() {
18
+ return true;
19
+ }
20
+
21
+ export const setSessionLocation = jest.fn(() => Promise.resolve());
22
+
23
+ export const mockStores = availableStores;
24
+
25
+ export function createGlobalStore<TState>(
26
+ name: string,
27
+ initialState: TState
28
+ ): Store<TState> {
29
+ const available = availableStores[name];
30
+
31
+ if (available) {
32
+ if (available.active) {
33
+ console.error(
34
+ "Cannot override an existing store. Make sure that stores are only created once."
35
+ );
36
+ } else {
37
+ available.value.setState(initialState, true);
38
+ }
39
+
40
+ available.active = true;
41
+ return available.value;
42
+ } else {
43
+ const store = createStore(initialState);
44
+ initialStates[name] = initialState;
45
+
46
+ availableStores[name] = {
47
+ value: store,
48
+ active: true,
49
+ };
50
+
51
+ return instrumentedStore(name, store);
52
+ }
53
+ }
54
+
55
+ export function getGlobalStore<TState = any>(
56
+ name: string,
57
+ fallbackState?: TState
58
+ ): Store<TState> {
59
+ const available = availableStores[name];
60
+
61
+ if (!available) {
62
+ const store = createStore(fallbackState);
63
+ initialStates[name] = fallbackState;
64
+ availableStores[name] = {
65
+ value: store,
66
+ active: false,
67
+ };
68
+ return instrumentedStore(name, store);
69
+ }
70
+
71
+ return instrumentedStore(name, available.value);
72
+ }
73
+
74
+ function instrumentedStore<T>(name: string, store: Store<T>) {
75
+ return {
76
+ action: jest.spyOn(store, "action"),
77
+ getState: jest.spyOn(store, "getState"),
78
+ setState: jest.spyOn(store, "setState"),
79
+ subscribe: jest.spyOn(store, "subscribe"),
80
+ unsubscribe: jest.spyOn(store, "unsubscribe"),
81
+ resetMock: () => store.setState(initialStates[name]),
82
+ } as any as MockedStore<T>;
83
+ }
84
+
85
+ export const configInternalStore = createGlobalStore("config-internal", {
86
+ devDefaultsAreOn: false,
87
+ });
88
+
89
+ export const implementerToolsConfigStore = createGlobalStore(
90
+ "implementer-tools-config",
91
+ {}
92
+ );
93
+
94
+ export const temporaryConfigStore = createGlobalStore("temporary-config", {});
95
+
96
+ export enum Type {
97
+ Array = "Array",
98
+ Boolean = "Boolean",
99
+ ConceptUuid = "ConceptUuid",
100
+ Number = "Number",
101
+ Object = "Object",
102
+ String = "String",
103
+ UUID = "UUID",
104
+ }
105
+
106
+ export const validators = {
107
+ isBoolean: jest.fn(),
108
+ isString: jest.fn(),
109
+ isUuid: jest.fn(),
110
+ isObject: jest.fn(),
111
+ };
112
+
113
+ let configSchema = {};
114
+ function getDefaults(schema) {
115
+ let tmp = {};
116
+ for (let k of Object.keys(schema)) {
117
+ if (schema[k].hasOwnProperty("_default")) {
118
+ tmp[k] = schema[k]._default;
119
+ } else if (k.startsWith("_")) {
120
+ continue;
121
+ } else if (isOrdinaryObject(schema[k])) {
122
+ tmp[k] = getDefaults(schema[k]);
123
+ } else {
124
+ tmp[k] = schema[k];
125
+ }
126
+ }
127
+ return tmp;
128
+ }
129
+ function isOrdinaryObject(x) {
130
+ return !!x && x.constructor === Object;
131
+ }
132
+
133
+ export const getConfig = jest.fn().mockReturnValue(getDefaults(configSchema));
134
+
135
+ export const useConfig = jest.fn().mockReturnValue(getDefaults(configSchema));
136
+
137
+ export function defineConfigSchema(moduleName, schema) {
138
+ configSchema = schema;
139
+ }
140
+
141
+ export const createErrorHandler = () => jest.fn().mockReturnValue(never());
142
+
143
+ export const reportError = jest.fn().mockImplementation((error) => {
144
+ throw error;
145
+ });
146
+
147
+ export const switchTo = jest.fn();
148
+
149
+ export const UserHasAccessReact = (props: any) => props.children;
150
+
151
+ export const openmrsFetch = jest.fn(() => new Promise(() => {}));
152
+
153
+ export const openmrsObservableFetch = jest.fn(() =>
154
+ of({ data: { entry: [] } })
155
+ );
156
+
157
+ export const setIsUIEditorEnabled = (boolean): void => {};
158
+
159
+ export const useCurrentPatient = jest.fn(() => [null, null, null, null]);
160
+
161
+ export const useSessionUser = jest.fn(() => null);
162
+
163
+ export const useLayoutType = jest.fn(() => "desktop");
164
+
165
+ export const useExtensionSlot = jest.fn(() => ({
166
+ extensionSlotModuleName: "",
167
+ attachedExtensionSlotName: "",
168
+ extensionIdsToRender: [],
169
+ }));
170
+
171
+ export const useExtension = jest.fn(() => [React.createRef(), undefined]);
172
+
173
+ export const getCurrentPatient = jest.fn(() =>
174
+ jest.fn().mockReturnValue(never())
175
+ );
176
+
177
+ export function getCurrentUser() {
178
+ return of({ authenticated: false });
179
+ }
180
+
181
+ export const navigate = jest.fn();
182
+
183
+ export const interpolateString = jest.fn();
184
+
185
+ export const getCurrentPatientUuid = jest.fn();
186
+
187
+ export const newWorkspaceItem = jest.fn();
188
+
189
+ export const fhirBaseUrl = "/ws/fhir2/R4";
190
+
191
+ export const ExtensionSlot = ({ children }) => <>{children}</>;
192
+
193
+ export const Extension = jest.fn().mockImplementation((props: any) => <slot />);
194
+
195
+ export const ConfigurableLink = jest
196
+ .fn()
197
+ .mockImplementation((config: { to: string; children: React.ReactNode }) => (
198
+ <a href={interpolateString(config.to)}>{config.children}</a>
199
+ ));
200
+
201
+ let state = { slots: {}, extensions: {} };
202
+
203
+ export const extensionStore = {
204
+ getState: () => state,
205
+ setState: (val) => {
206
+ state = { ...state, ...val };
207
+ },
208
+ subscribe: (updateFcn) => {
209
+ updateFcn(state);
210
+ return () => {};
211
+ },
212
+ unsubscribe: () => {},
213
+ };
214
+
215
+ export const ComponentContext = React.createContext(null);
216
+
217
+ export const openmrsComponentDecorator = jest
218
+ .fn()
219
+ .mockImplementation(() => (component) => component);
220
+
221
+ export const UserHasAccess = jest.fn().mockImplementation((props: any) => {
222
+ return props.children;
223
+ });
224
+
225
+ export const createUseStore = (store: Store<any>) => (actions) => {
226
+ const state = store.getState();
227
+ return { ...state, ...actions };
228
+ };
229
+
230
+ export const useExtensionStore = (actions) => {
231
+ const state = extensionStore.getState();
232
+ return { ...state, ...actions };
233
+ };
234
+
235
+ export const useStore = (store: Store<any>, actions) => {
236
+ const state = store.getState();
237
+ return { ...state, ...actions };
238
+ };
239
+
240
+ export const showNotification = jest.fn();
241
+ export const showToast = jest.fn();
242
+
243
+ export function setupPaths(config: any) {
244
+ window.openmrsBase = config.apiUrl;
245
+ window.spaBase = config.spaPath;
246
+ window.spaEnv = config.env || "production";
247
+ window.spaVersion = process.env.BUILD_VERSION;
248
+ window.getOpenmrsSpaBase = () => `${window.spaBase}/`;
249
+ }
250
+
251
+ export const attach = jest.fn();
252
+ export const detach = jest.fn();
253
+ export const detachAll = jest.fn();