@openmrs/esm-framework 3.1.15-pre.752 → 3.1.15-pre.761

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,44 @@ 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 extensionStore = getGlobalStore("extensions", { slots: {} });
207
+
208
+ /* esm-react-utils */
209
+
210
+ export const ComponentContext = React.createContext(null);
157
211
 
158
- export const setIsUIEditorEnabled = (boolean): void => {};
212
+ export const openmrsComponentDecorator = jest
213
+ .fn()
214
+ .mockImplementation(() => (component) => component);
159
215
 
160
216
  export const useCurrentPatient = jest.fn(() => [null, null, null, null]);
161
217
 
@@ -169,51 +225,6 @@ export const useExtensionSlot = jest.fn(() => ({
169
225
  extensionIdsToRender: [],
170
226
  }));
171
227
 
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
- export const getExtensionStore = () =>
203
- getGlobalStore("extensions", { slots: {} });
204
-
205
- export const getExtensionInternalStore = () =>
206
- getGlobalStore("extensions-internal", {
207
- slots: {},
208
- extensions: {},
209
- });
210
-
211
- export const ComponentContext = React.createContext(null);
212
-
213
- export const openmrsComponentDecorator = jest
214
- .fn()
215
- .mockImplementation(() => (component) => component);
216
-
217
228
  export const UserHasAccess = jest.fn().mockImplementation((props: any) => {
218
229
  return props.children;
219
230
  });
@@ -223,32 +234,16 @@ export const createUseStore = (store: Store<any>) => (actions) => {
223
234
  return { ...state, ...actions };
224
235
  };
225
236
 
226
- export const useExtensionInternalStore = createUseStore(
227
- getExtensionInternalStore()
228
- );
229
-
230
- export const useExtensionStore = createUseStore(getExtensionStore());
237
+ export const useExtensionStore = (actions) => {
238
+ const state = extensionStore.getState();
239
+ return { ...state, ...actions };
240
+ };
231
241
 
232
242
  export const useStore = (store: Store<any>, actions) => {
233
243
  const state = store.getState();
234
244
  return { ...state, ...actions };
235
245
  };
236
246
 
237
- export const showNotification = jest.fn();
238
- export const showToast = jest.fn();
239
-
240
- export function setupPaths(config: any) {
241
- window.openmrsBase = config.apiUrl;
242
- window.spaBase = config.spaPath;
243
- window.spaEnv = config.env || "production";
244
- window.spaVersion = process.env.BUILD_VERSION;
245
- window.getOpenmrsSpaBase = () => `${window.spaBase}/`;
246
- }
247
-
248
- export const attach = jest.fn();
249
- export const detach = jest.fn();
250
- export const detachAll = jest.fn();
251
-
252
247
  export const usePagination = jest.fn().mockImplementation(() => ({
253
248
  currentPage: 1,
254
249
  goTo: () => {},
@@ -257,27 +252,7 @@ export const usePagination = jest.fn().mockImplementation(() => ({
257
252
 
258
253
  export const useVisitTypes = jest.fn(() => []);
259
254
 
260
- export const formatDate = jest.fn((date: Date, mode) => {
261
- if (!mode || mode == "standard") {
262
- return dayjs(date).format("DD-MMM-YYYY");
263
- }
264
- if (mode == "wide") {
265
- return dayjs(date).format("DD - MMM - YYYY");
266
- }
267
- if (mode == "no day") {
268
- return dayjs(date).format("MMM YYYY");
269
- }
270
- if (mode == "no year") {
271
- return dayjs(date).format("DD MMM");
272
- }
273
- console.warn("Unknown formatDate mode: ", mode);
274
- return dayjs(date).format("DD-MMM-YYYY");
275
- });
276
-
277
- export const formatTime = jest.fn((date: Date) => {
278
- return dayjs(date).format("HH:mm");
279
- });
255
+ /* esm-styleguide */
280
256
 
281
- export const formatDatetime = jest.fn((date: Date, mode) => {
282
- return formatDate(date, mode) + " " + formatTime(date);
283
- });
257
+ export const showNotification = jest.fn();
258
+ 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.752",
3
+ "version": "3.1.15-pre.761",
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.752",
39
- "@openmrs/esm-breadcrumbs": "^3.1.15-pre.752",
40
- "@openmrs/esm-config": "^3.1.15-pre.752",
41
- "@openmrs/esm-error-handling": "^3.1.15-pre.752",
42
- "@openmrs/esm-extensions": "^3.1.15-pre.752",
43
- "@openmrs/esm-globals": "^3.1.15-pre.752",
44
- "@openmrs/esm-offline": "^3.1.15-pre.752",
45
- "@openmrs/esm-react-utils": "^3.1.15-pre.752",
46
- "@openmrs/esm-state": "^3.1.15-pre.752",
47
- "@openmrs/esm-styleguide": "^3.1.15-pre.752",
48
- "@openmrs/esm-utils": "^3.1.15-pre.752",
38
+ "@openmrs/esm-api": "^3.1.15-pre.761",
39
+ "@openmrs/esm-breadcrumbs": "^3.1.15-pre.761",
40
+ "@openmrs/esm-config": "^3.1.15-pre.761",
41
+ "@openmrs/esm-error-handling": "^3.1.15-pre.761",
42
+ "@openmrs/esm-extensions": "^3.1.15-pre.761",
43
+ "@openmrs/esm-globals": "^3.1.15-pre.761",
44
+ "@openmrs/esm-offline": "^3.1.15-pre.761",
45
+ "@openmrs/esm-react-utils": "^3.1.15-pre.761",
46
+ "@openmrs/esm-state": "^3.1.15-pre.761",
47
+ "@openmrs/esm-styleguide": "^3.1.15-pre.761",
48
+ "@openmrs/esm-utils": "^3.1.15-pre.761",
49
49
  "dayjs": "^1.10.7"
50
50
  },
51
- "gitHead": "c0944ed45eaf5b0aa1c0f9f9da63da07a31edbf3"
51
+ "gitHead": "92dcde2d52edfb326b99f985cdec3700a0420add"
52
52
  }
@@ -2,9 +2,12 @@ import React from "react";
2
2
  import {
3
3
  attach,
4
4
  registerExtension,
5
- updateInternalExtensionStore,
5
+ registerExtensionSlot,
6
+ updateExtensionStore,
7
+ ExtensionStore,
6
8
  } from "../../../esm-extensions";
7
9
  import {
10
+ Extension,
8
11
  ExtensionSlot,
9
12
  getSyncLifecycle,
10
13
  openmrsComponentDecorator,
@@ -15,7 +18,7 @@ import { render, screen, waitFor } from "@testing-library/react";
15
18
 
16
19
  describe("Interaction between configuration and extension systems", () => {
17
20
  beforeEach(() => {
18
- updateInternalExtensionStore(() => ({ slots: {}, extensions: {} }));
21
+ updateExtensionStore(() => ({ slots: {}, extensions: {} }));
19
22
  });
20
23
 
21
24
  test("Config should add, order, and remove extensions within slots", async () => {
@@ -23,6 +26,7 @@ describe("Interaction between configuration and extension systems", () => {
23
26
  registerSimpleExtension("Wilma", "esm-flintstone");
24
27
  registerSimpleExtension("Barney", "esm-rubble");
25
28
  registerSimpleExtension("Betty", "esm-rubble");
29
+ registerExtensionSlot("esm-flintstone", "A slot");
26
30
  attach("A slot", "Fred");
27
31
  attach("A slot", "Wilma");
28
32
  defineConfigSchema("esm-flintstone", {});
@@ -54,6 +58,8 @@ describe("Interaction between configuration and extension systems", () => {
54
58
 
55
59
  test("Extensions should recieve config from module and from 'configure' key", async () => {
56
60
  registerSimpleExtension("Wilma", "esm-flintstone", true);
61
+ registerExtensionSlot("esm-flintstone", "Flintstone slot");
62
+ registerExtensionSlot("esm-flintstone", "Future slot");
57
63
  defineConfigSchema("esm-flintstone", {
58
64
  town: { _type: Type.String, _default: "Bedrock" },
59
65
  });
@@ -99,6 +105,7 @@ describe("Interaction between configuration and extension systems", () => {
99
105
 
100
106
  test("Should be possible to attach the same extension twice with different configurations", async () => {
101
107
  registerSimpleExtension("pet", "esm-characters", true);
108
+ registerExtensionSlot("esm-flintstone", "Flintstone slot");
102
109
  defineConfigSchema("esm-characters", {
103
110
  name: { _type: Type.String, _default: "(no-name)" },
104
111
  });
@@ -154,8 +161,7 @@ function registerSimpleExtension(
154
161
  </div>
155
162
  );
156
163
  };
157
- registerExtension({
158
- name,
164
+ registerExtension(name, {
159
165
  moduleName,
160
166
  load: getSyncLifecycle(
161
167
  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,63 +0,0 @@
1
- [@openmrs/esm-framework](../API.md) / AssignedExtension
2
-
3
- # Interface: AssignedExtension
4
-
5
- ## Table of contents
6
-
7
- ### Properties
8
-
9
- - [id](AssignedExtension.md#id)
10
- - [meta](AssignedExtension.md#meta)
11
- - [name](AssignedExtension.md#name)
12
- - [offline](AssignedExtension.md#offline)
13
- - [online](AssignedExtension.md#online)
14
-
15
- ## Properties
16
-
17
- ### id
18
-
19
- • **id**: `string`
20
-
21
- #### Defined in
22
-
23
- [packages/framework/esm-extensions/src/store.ts:71](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L71)
24
-
25
- ___
26
-
27
- ### meta
28
-
29
- • **meta**: [`ExtensionMeta`](ExtensionMeta.md)
30
-
31
- #### Defined in
32
-
33
- [packages/framework/esm-extensions/src/store.ts:73](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L73)
34
-
35
- ___
36
-
37
- ### name
38
-
39
- • **name**: `string`
40
-
41
- #### Defined in
42
-
43
- [packages/framework/esm-extensions/src/store.ts:72](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L72)
44
-
45
- ___
46
-
47
- ### offline
48
-
49
- • `Optional` **offline**: `boolean` \| `object`
50
-
51
- #### Defined in
52
-
53
- [packages/framework/esm-extensions/src/store.ts:75](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L75)
54
-
55
- ___
56
-
57
- ### online
58
-
59
- • `Optional` **online**: `boolean` \| `object`
60
-
61
- #### Defined in
62
-
63
- [packages/framework/esm-extensions/src/store.ts:74](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L74)
@@ -1,34 +0,0 @@
1
- [@openmrs/esm-framework](../API.md) / ExtensionInternalStore
2
-
3
- # Interface: ExtensionInternalStore
4
-
5
- ## Table of contents
6
-
7
- ### Properties
8
-
9
- - [extensions](ExtensionInternalStore.md#extensions)
10
- - [slots](ExtensionInternalStore.md#slots)
11
-
12
- ## Properties
13
-
14
- ### extensions
15
-
16
- • **extensions**: `Record`<`string`, [`ExtensionInfo`](ExtensionInfo.md)\>
17
-
18
- Extensions indexed by name
19
-
20
- #### Defined in
21
-
22
- [packages/framework/esm-extensions/src/store.ts:39](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L39)
23
-
24
- ___
25
-
26
- ### slots
27
-
28
- • **slots**: `Record`<`string`, [`ExtensionSlotInfo`](ExtensionSlotInfo.md)\>
29
-
30
- Slots indexed by name
31
-
32
- #### Defined in
33
-
34
- [packages/framework/esm-extensions/src/store.ts:37](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L37)
@@ -1,30 +0,0 @@
1
- [@openmrs/esm-framework](../API.md) / ExtensionSlotState
2
-
3
- # Interface: ExtensionSlotState
4
-
5
- ## Table of contents
6
-
7
- ### Properties
8
-
9
- - [assignedExtensions](ExtensionSlotState.md#assignedextensions)
10
- - [moduleName](ExtensionSlotState.md#modulename)
11
-
12
- ## Properties
13
-
14
- ### assignedExtensions
15
-
16
- • **assignedExtensions**: [`AssignedExtension`](AssignedExtension.md)[]
17
-
18
- #### Defined in
19
-
20
- [packages/framework/esm-extensions/src/store.ts:67](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L67)
21
-
22
- ___
23
-
24
- ### moduleName
25
-
26
- • **moduleName**: `string`
27
-
28
- #### Defined in
29
-
30
- [packages/framework/esm-extensions/src/store.ts:66](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-extensions/src/store.ts#L66)