@openmrs/esm-framework 3.1.15-pre.749 → 3.1.15-pre.757

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/mock.tsx CHANGED
@@ -2,8 +2,48 @@ import React from "react";
2
2
  import type {} from "@openmrs/esm-globals";
3
3
  import createStore, { Store } from "unistore";
4
4
  import { never, of } from "rxjs";
5
- import dayjs from "dayjs";
5
+ export {
6
+ parseDate,
7
+ formatDate,
8
+ formatDatetime,
9
+ formatTime,
10
+ } from "@openmrs/esm-utils";
6
11
 
12
+ window.i18next = { ...window.i18next, language: "en" };
13
+
14
+ /* esm-globals */
15
+
16
+ export function setupPaths(config: any) {
17
+ window.openmrsBase = config.apiUrl;
18
+ window.spaBase = config.spaPath;
19
+ window.spaEnv = config.env || "production";
20
+ window.spaVersion = process.env.BUILD_VERSION;
21
+ window.getOpenmrsSpaBase = () => `${window.spaBase}/`;
22
+ }
23
+
24
+ /* esm-utils */
25
+ export function isVersionSatisfied() {
26
+ return true;
27
+ }
28
+
29
+ /* esm-api */
30
+ export const setSessionLocation = jest.fn(() => Promise.resolve());
31
+
32
+ export const openmrsFetch = jest.fn(() => new Promise(() => {}));
33
+
34
+ export const openmrsObservableFetch = jest.fn(() =>
35
+ of({ data: { entry: [] } })
36
+ );
37
+
38
+ export function getCurrentUser() {
39
+ return of({ authenticated: false });
40
+ }
41
+
42
+ export const newWorkspaceItem = jest.fn();
43
+
44
+ export const fhirBaseUrl = "/ws/fhir2/R4";
45
+
46
+ /* esm-state */
7
47
  interface StoreEntity {
8
48
  value: Store<any>;
9
49
  active: boolean;
@@ -15,12 +55,6 @@ const initialStates: Record<string, any> = {};
15
55
 
16
56
  const availableStores: Record<string, StoreEntity> = {};
17
57
 
18
- export function isVersionSatisfied() {
19
- return true;
20
- }
21
-
22
- export const setSessionLocation = jest.fn(() => Promise.resolve());
23
-
24
58
  export const mockStores = availableStores;
25
59
 
26
60
  export function createGlobalStore<TState>(
@@ -83,6 +117,7 @@ function instrumentedStore<T>(name: string, store: Store<T>) {
83
117
  } as any as MockedStore<T>;
84
118
  }
85
119
 
120
+ /* esm-config */
86
121
  export const configInternalStore = createGlobalStore("config-internal", {
87
122
  devDefaultsAreOn: false,
88
123
  });
@@ -139,23 +174,51 @@ export function defineConfigSchema(moduleName, schema) {
139
174
  configSchema = schema;
140
175
  }
141
176
 
177
+ export const navigate = jest.fn();
178
+
179
+ export const interpolateString = jest.fn();
180
+
181
+ export const ConfigurableLink = jest
182
+ .fn()
183
+ .mockImplementation((config: { to: string; children: React.ReactNode }) => (
184
+ <a href={interpolateString(config.to)}>{config.children}</a>
185
+ ));
186
+
187
+ /* esm-error-handling */
142
188
  export const createErrorHandler = () => jest.fn().mockReturnValue(never());
143
189
 
144
190
  export const reportError = jest.fn().mockImplementation((error) => {
145
191
  throw error;
146
192
  });
147
193
 
194
+ /* esm-extensions */
195
+
196
+ export const attach = jest.fn();
197
+ export const detach = jest.fn();
198
+ export const detachAll = jest.fn();
199
+
148
200
  export const switchTo = jest.fn();
149
201
 
150
- export const UserHasAccessReact = (props: any) => props.children;
202
+ export const ExtensionSlot = ({ children }) => <>{children}</>;
151
203
 
152
- export const openmrsFetch = jest.fn(() => new Promise(() => {}));
204
+ export const Extension = jest.fn().mockImplementation((props: any) => <slot />);
153
205
 
154
- export const openmrsObservableFetch = jest.fn(() =>
155
- of({ data: { entry: [] } })
156
- );
206
+ export const getExtensionStore = () =>
207
+ getGlobalStore("extensions", { slots: {} });
208
+
209
+ export const getExtensionInternalStore = () =>
210
+ getGlobalStore("extensions-internal", {
211
+ slots: {},
212
+ extensions: {},
213
+ });
214
+
215
+ /* esm-react-utils */
216
+
217
+ export const ComponentContext = React.createContext(null);
157
218
 
158
- export const setIsUIEditorEnabled = (boolean): void => {};
219
+ export const openmrsComponentDecorator = jest
220
+ .fn()
221
+ .mockImplementation(() => (component) => component);
159
222
 
160
223
  export const useCurrentPatient = jest.fn(() => [null, null, null, null]);
161
224
 
@@ -169,56 +232,6 @@ export const useExtensionSlot = jest.fn(() => ({
169
232
  extensionIdsToRender: [],
170
233
  }));
171
234
 
172
- export const useExtension = jest.fn(() => [React.createRef(), undefined]);
173
-
174
- export const getCurrentPatient = jest.fn(() =>
175
- jest.fn().mockReturnValue(never())
176
- );
177
-
178
- export function getCurrentUser() {
179
- return of({ authenticated: false });
180
- }
181
-
182
- export const navigate = jest.fn();
183
-
184
- export const interpolateString = jest.fn();
185
-
186
- export const getCurrentPatientUuid = jest.fn();
187
-
188
- export const newWorkspaceItem = jest.fn();
189
-
190
- export const fhirBaseUrl = "/ws/fhir2/R4";
191
-
192
- export const ExtensionSlot = ({ children }) => <>{children}</>;
193
-
194
- export const Extension = jest.fn().mockImplementation((props: any) => <slot />);
195
-
196
- export const ConfigurableLink = jest
197
- .fn()
198
- .mockImplementation((config: { to: string; children: React.ReactNode }) => (
199
- <a href={interpolateString(config.to)}>{config.children}</a>
200
- ));
201
-
202
- let state = { slots: {}, extensions: {} };
203
-
204
- export const extensionStore = {
205
- getState: () => state,
206
- setState: (val) => {
207
- state = { ...state, ...val };
208
- },
209
- subscribe: (updateFcn) => {
210
- updateFcn(state);
211
- return () => {};
212
- },
213
- unsubscribe: () => {},
214
- };
215
-
216
- export const ComponentContext = React.createContext(null);
217
-
218
- export const openmrsComponentDecorator = jest
219
- .fn()
220
- .mockImplementation(() => (component) => component);
221
-
222
235
  export const UserHasAccess = jest.fn().mockImplementation((props: any) => {
223
236
  return props.children;
224
237
  });
@@ -228,31 +241,17 @@ export const createUseStore = (store: Store<any>) => (actions) => {
228
241
  return { ...state, ...actions };
229
242
  };
230
243
 
231
- export const useExtensionStore = (actions) => {
232
- const state = extensionStore.getState();
233
- return { ...state, ...actions };
234
- };
244
+ export const useExtensionInternalStore = createUseStore(
245
+ getExtensionInternalStore()
246
+ );
247
+
248
+ export const useExtensionStore = createUseStore(getExtensionStore());
235
249
 
236
250
  export const useStore = (store: Store<any>, actions) => {
237
251
  const state = store.getState();
238
252
  return { ...state, ...actions };
239
253
  };
240
254
 
241
- export const showNotification = jest.fn();
242
- export const showToast = jest.fn();
243
-
244
- export function setupPaths(config: any) {
245
- window.openmrsBase = config.apiUrl;
246
- window.spaBase = config.spaPath;
247
- window.spaEnv = config.env || "production";
248
- window.spaVersion = process.env.BUILD_VERSION;
249
- window.getOpenmrsSpaBase = () => `${window.spaBase}/`;
250
- }
251
-
252
- export const attach = jest.fn();
253
- export const detach = jest.fn();
254
- export const detachAll = jest.fn();
255
-
256
255
  export const usePagination = jest.fn().mockImplementation(() => ({
257
256
  currentPage: 1,
258
257
  goTo: () => {},
@@ -261,27 +260,7 @@ export const usePagination = jest.fn().mockImplementation(() => ({
261
260
 
262
261
  export const useVisitTypes = jest.fn(() => []);
263
262
 
264
- export const formatDate = jest.fn((date: Date, mode) => {
265
- if (!mode || mode == "standard") {
266
- return dayjs(date).format("DD-MMM-YYYY");
267
- }
268
- if (mode == "wide") {
269
- return dayjs(date).format("DD - MMM - YYYY");
270
- }
271
- if (mode == "no day") {
272
- return dayjs(date).format("MMM YYYY");
273
- }
274
- if (mode == "no year") {
275
- return dayjs(date).format("DD MMM");
276
- }
277
- console.warn("Unknown formatDate mode: ", mode);
278
- return dayjs(date).format("DD-MMM-YYYY");
279
- });
280
-
281
- export const formatTime = jest.fn((date: Date) => {
282
- return dayjs(date).format("HH:mm");
283
- });
263
+ /* esm-styleguide */
284
264
 
285
- export const formatDatetime = jest.fn((date: Date, mode) => {
286
- return formatDate(date, mode) + " " + formatTime(date);
287
- });
265
+ export const showNotification = jest.fn();
266
+ export const showToast = jest.fn();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-framework",
3
- "version": "3.1.15-pre.749",
3
+ "version": "3.1.15-pre.757",
4
4
  "license": "MPL-2.0",
5
5
  "browser": "dist/openmrs-esm-framework.js",
6
6
  "main": "src/index.ts",
@@ -35,18 +35,18 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@openmrs/esm-api": "^3.1.15-pre.749",
39
- "@openmrs/esm-breadcrumbs": "^3.1.15-pre.749",
40
- "@openmrs/esm-config": "^3.1.15-pre.749",
41
- "@openmrs/esm-error-handling": "^3.1.15-pre.749",
42
- "@openmrs/esm-extensions": "^3.1.15-pre.749",
43
- "@openmrs/esm-globals": "^3.1.15-pre.749",
44
- "@openmrs/esm-offline": "^3.1.15-pre.749",
45
- "@openmrs/esm-react-utils": "^3.1.15-pre.749",
46
- "@openmrs/esm-state": "^3.1.15-pre.749",
47
- "@openmrs/esm-styleguide": "^3.1.15-pre.749",
48
- "@openmrs/esm-utils": "^3.1.15-pre.749",
38
+ "@openmrs/esm-api": "^3.1.15-pre.757",
39
+ "@openmrs/esm-breadcrumbs": "^3.1.15-pre.757",
40
+ "@openmrs/esm-config": "^3.1.15-pre.757",
41
+ "@openmrs/esm-error-handling": "^3.1.15-pre.757",
42
+ "@openmrs/esm-extensions": "^3.1.15-pre.757",
43
+ "@openmrs/esm-globals": "^3.1.15-pre.757",
44
+ "@openmrs/esm-offline": "^3.1.15-pre.757",
45
+ "@openmrs/esm-react-utils": "^3.1.15-pre.757",
46
+ "@openmrs/esm-state": "^3.1.15-pre.757",
47
+ "@openmrs/esm-styleguide": "^3.1.15-pre.757",
48
+ "@openmrs/esm-utils": "^3.1.15-pre.757",
49
49
  "dayjs": "^1.10.7"
50
50
  },
51
- "gitHead": "110be85fd4162b3c89f51898a8f5913bec0b15ba"
51
+ "gitHead": "9b005ddcbb5f1f0412081c7c85b5afbe4477b17e"
52
52
  }
@@ -2,12 +2,9 @@ import React from "react";
2
2
  import {
3
3
  attach,
4
4
  registerExtension,
5
- registerExtensionSlot,
6
- updateExtensionStore,
7
- ExtensionStore,
5
+ updateInternalExtensionStore,
8
6
  } from "../../../esm-extensions";
9
7
  import {
10
- Extension,
11
8
  ExtensionSlot,
12
9
  getSyncLifecycle,
13
10
  openmrsComponentDecorator,
@@ -18,7 +15,7 @@ import { render, screen, waitFor } from "@testing-library/react";
18
15
 
19
16
  describe("Interaction between configuration and extension systems", () => {
20
17
  beforeEach(() => {
21
- updateExtensionStore(() => ({ slots: {}, extensions: {} }));
18
+ updateInternalExtensionStore(() => ({ slots: {}, extensions: {} }));
22
19
  });
23
20
 
24
21
  test("Config should add, order, and remove extensions within slots", async () => {
@@ -26,7 +23,6 @@ describe("Interaction between configuration and extension systems", () => {
26
23
  registerSimpleExtension("Wilma", "esm-flintstone");
27
24
  registerSimpleExtension("Barney", "esm-rubble");
28
25
  registerSimpleExtension("Betty", "esm-rubble");
29
- registerExtensionSlot("esm-flintstone", "A slot");
30
26
  attach("A slot", "Fred");
31
27
  attach("A slot", "Wilma");
32
28
  defineConfigSchema("esm-flintstone", {});
@@ -58,8 +54,6 @@ describe("Interaction between configuration and extension systems", () => {
58
54
 
59
55
  test("Extensions should recieve config from module and from 'configure' key", async () => {
60
56
  registerSimpleExtension("Wilma", "esm-flintstone", true);
61
- registerExtensionSlot("esm-flintstone", "Flintstone slot");
62
- registerExtensionSlot("esm-flintstone", "Future slot");
63
57
  defineConfigSchema("esm-flintstone", {
64
58
  town: { _type: Type.String, _default: "Bedrock" },
65
59
  });
@@ -105,7 +99,6 @@ describe("Interaction between configuration and extension systems", () => {
105
99
 
106
100
  test("Should be possible to attach the same extension twice with different configurations", async () => {
107
101
  registerSimpleExtension("pet", "esm-characters", true);
108
- registerExtensionSlot("esm-flintstone", "Flintstone slot");
109
102
  defineConfigSchema("esm-characters", {
110
103
  name: { _type: Type.String, _default: "(no-name)" },
111
104
  });
@@ -161,7 +154,8 @@ function registerSimpleExtension(
161
154
  </div>
162
155
  );
163
156
  };
164
- registerExtension(name, {
157
+ registerExtension({
158
+ name,
165
159
  moduleName,
166
160
  load: getSyncLifecycle(
167
161
  takesConfig ? ConfigurableComponent : SimpleComponent,
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A test that validates that `@openmrs/esm-framework/mock` has
3
+ * the same API as `@openmrs/esm-framework`.
4
+ *
5
+ * Disabled because the mock is nowhere close to having the same
6
+ * API. You can change `xit` to `it` to run the test and see a
7
+ * comparison of the exports of the two modules.
8
+ */
9
+
10
+ import * as real from "./index";
11
+ import * as mock from "../mock";
12
+
13
+ describe("@openmrs/esm-framework/mock", () => {
14
+ xit("should have the same exports as @openmrs/esm-framework", () => {
15
+ expect(new Set(Object.keys(real))).toEqual(new Set(Object.keys(mock)));
16
+ });
17
+ });
@@ -1,34 +0,0 @@
1
- [@openmrs/esm-framework](../API.md) / ConfigStore
2
-
3
- # Interface: ConfigStore
4
-
5
- Output configs
6
-
7
- Each module has its own stores for its config and its extension slots' configs.
8
-
9
- ## Table of contents
10
-
11
- ### Properties
12
-
13
- - [config](ConfigStore.md#config)
14
- - [loaded](ConfigStore.md#loaded)
15
-
16
- ## Properties
17
-
18
- ### config
19
-
20
- • **config**: ``null`` \| [`ConfigObject`](ConfigObject.md)
21
-
22
- #### Defined in
23
-
24
- [packages/framework/esm-config/src/module-config/state.ts:125](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-config/src/module-config/state.ts#L125)
25
-
26
- ___
27
-
28
- ### loaded
29
-
30
- • **loaded**: `boolean`
31
-
32
- #### Defined in
33
-
34
- [packages/framework/esm-config/src/module-config/state.ts:126](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-config/src/module-config/state.ts#L126)
@@ -1,81 +0,0 @@
1
- [@openmrs/esm-framework](../API.md) / ExtensionDetails
2
-
3
- # Interface: ExtensionDetails
4
-
5
- ## Table of contents
6
-
7
- ### Properties
8
-
9
- - [meta](ExtensionDetails.md#meta)
10
- - [moduleName](ExtensionDetails.md#modulename)
11
- - [offline](ExtensionDetails.md#offline)
12
- - [online](ExtensionDetails.md#online)
13
- - [order](ExtensionDetails.md#order)
14
-
15
- ### Methods
16
-
17
- - [load](ExtensionDetails.md#load)
18
-
19
- ## Properties
20
-
21
- ### meta
22
-
23
- • **meta**: `Record`<`string`, `any`\>
24
-
25
- #### Defined in
26
-
27
- [packages/framework/esm-extensions/src/extensions.ts:56](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/extensions.ts#L56)
28
-
29
- ___
30
-
31
- ### moduleName
32
-
33
- • **moduleName**: `string`
34
-
35
- #### Defined in
36
-
37
- [packages/framework/esm-extensions/src/extensions.ts:54](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/extensions.ts#L54)
38
-
39
- ___
40
-
41
- ### offline
42
-
43
- • `Optional` **offline**: `boolean` \| `object`
44
-
45
- #### Defined in
46
-
47
- [packages/framework/esm-extensions/src/extensions.ts:58](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/extensions.ts#L58)
48
-
49
- ___
50
-
51
- ### online
52
-
53
- • `Optional` **online**: `boolean` \| `object`
54
-
55
- #### Defined in
56
-
57
- [packages/framework/esm-extensions/src/extensions.ts:57](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/extensions.ts#L57)
58
-
59
- ___
60
-
61
- ### order
62
-
63
- • `Optional` **order**: `number`
64
-
65
- #### Defined in
66
-
67
- [packages/framework/esm-extensions/src/extensions.ts:59](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/extensions.ts#L59)
68
-
69
- ## Methods
70
-
71
- ### load
72
-
73
- ▸ **load**(): `Promise`<`any`\>
74
-
75
- #### Returns
76
-
77
- `Promise`<`any`\>
78
-
79
- #### Defined in
80
-
81
- [packages/framework/esm-extensions/src/extensions.ts:55](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/extensions.ts#L55)
@@ -1,32 +0,0 @@
1
- [@openmrs/esm-framework](../API.md) / ExtensionSlotConfigsStore
2
-
3
- # Interface: ExtensionSlotConfigsStore
4
-
5
- ## Table of contents
6
-
7
- ### Properties
8
-
9
- - [extensionSlotConfigs](ExtensionSlotConfigsStore.md#extensionslotconfigs)
10
- - [loaded](ExtensionSlotConfigsStore.md#loaded)
11
-
12
- ## Properties
13
-
14
- ### extensionSlotConfigs
15
-
16
- • **extensionSlotConfigs**: `Record`<`string`, [`ExtensionSlotConfigObject`](ExtensionSlotConfigObject.md)\>
17
-
18
- Configs for each extension slot in the module, indexed by slot name
19
-
20
- #### Defined in
21
-
22
- [packages/framework/esm-config/src/module-config/state.ts:146](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-config/src/module-config/state.ts#L146)
23
-
24
- ___
25
-
26
- ### loaded
27
-
28
- • **loaded**: `boolean`
29
-
30
- #### Defined in
31
-
32
- [packages/framework/esm-config/src/module-config/state.ts:147](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-config/src/module-config/state.ts#L147)
@@ -1,51 +0,0 @@
1
- [@openmrs/esm-framework](../API.md) / ExtensionSlotInstance
2
-
3
- # Interface: ExtensionSlotInstance
4
-
5
- ## Table of contents
6
-
7
- ### Properties
8
-
9
- - [addedIds](ExtensionSlotInstance.md#addedids)
10
- - [idOrder](ExtensionSlotInstance.md#idorder)
11
- - [removedIds](ExtensionSlotInstance.md#removedids)
12
-
13
- ## Properties
14
-
15
- ### addedIds
16
-
17
- • **addedIds**: `string`[]
18
-
19
- A set of additional extension IDs which have been added to to this slot despite not being
20
- explicitly `attach`ed to it.
21
- An example may be an extension which is added to the slot via the configuration.
22
-
23
- #### Defined in
24
-
25
- [packages/framework/esm-extensions/src/store.ts:47](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L47)
26
-
27
- ___
28
-
29
- ### idOrder
30
-
31
- • **idOrder**: `string`[]
32
-
33
- A set allowing explicit ordering of the `assignedIds`.
34
-
35
- #### Defined in
36
-
37
- [packages/framework/esm-extensions/src/store.ts:57](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L57)
38
-
39
- ___
40
-
41
- ### removedIds
42
-
43
- • **removedIds**: `string`[]
44
-
45
- A set of extension IDs which have been removed/hidden from this slot, even though they have
46
- previously been `attach`ed/added to it.
47
- An example may be an extension which is removed from the slot via the configuration.
48
-
49
- #### Defined in
50
-
51
- [packages/framework/esm-extensions/src/store.ts:53](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L53)
@@ -1,19 +0,0 @@
1
- [@openmrs/esm-framework](../API.md) / ImplementerToolsConfigStore
2
-
3
- # Interface: ImplementerToolsConfigStore
4
-
5
- ## Table of contents
6
-
7
- ### Properties
8
-
9
- - [config](ImplementerToolsConfigStore.md#config)
10
-
11
- ## Properties
12
-
13
- ### config
14
-
15
- • **config**: [`Config`](Config.md)
16
-
17
- #### Defined in
18
-
19
- [packages/framework/esm-config/src/module-config/state.ts:179](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-config/src/module-config/state.ts#L179)