@openmrs/esm-react-utils 5.3.3-pre.1237 → 5.3.3-pre.1247
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/__mocks__/openmrs-esm-state.mock.ts +8 -20
- package/dist/openmrs-esm-react-utils.js.map +1 -1
- package/jest.config.js +9 -11
- package/package.json +7 -7
- package/src/ComponentContext.ts +2 -2
- package/src/ConfigurableLink.test.tsx +19 -23
- package/src/ConfigurableLink.tsx +5 -19
- package/src/Extension.tsx +36 -76
- package/src/ExtensionSlot.tsx +15 -24
- package/src/UserHasAccess.tsx +3 -7
- package/src/extensions.test.tsx +100 -179
- package/src/getLifecycle.ts +8 -18
- package/src/index.ts +31 -31
- package/src/openmrsComponentDecorator.test.tsx +12 -12
- package/src/openmrsComponentDecorator.tsx +12 -26
- package/src/public.ts +27 -27
- package/src/setup-tests.js +4 -4
- package/src/useAbortController.test.tsx +8 -8
- package/src/useAbortController.ts +1 -1
- package/src/useAssignedExtensionIds.ts +4 -5
- package/src/useAssignedExtensions.ts +3 -7
- package/src/useBodyScrollLock.ts +2 -2
- package/src/useConfig.test.tsx +96 -112
- package/src/useConfig.ts +15 -43
- package/src/useConnectedExtensions.ts +8 -17
- package/src/useConnectivity.ts +3 -6
- package/src/useDebounce.ts +1 -1
- package/src/useExtensionInternalStore.ts +3 -8
- package/src/useExtensionSlot.ts +5 -7
- package/src/useExtensionSlotMeta.ts +5 -11
- package/src/useExtensionStore.ts +3 -5
- package/src/useFeatureFlag.ts +4 -4
- package/src/useForceUpdate.ts +1 -1
- package/src/useLayoutType.ts +12 -13
- package/src/useLocations.tsx +3 -3
- package/src/useOnClickOutside.test.tsx +10 -10
- package/src/useOnClickOutside.ts +2 -5
- package/src/useOpenmrsSWR.ts +9 -9
- package/src/usePagination.ts +6 -18
- package/src/usePatient.ts +9 -13
- package/src/useSession.test.tsx +35 -43
- package/src/useSession.ts +9 -13
- package/src/useStore.test.ts +11 -13
- package/src/useStore.ts +10 -31
- package/src/useVisit.ts +14 -37
- package/src/useVisitTypes.ts +3 -3
- package/webpack.config.js +14 -14
package/src/public.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export { type ExtensionData } from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
21
|
-
export * from
|
|
22
|
-
export * from
|
|
23
|
-
export { useSession } from
|
|
24
|
-
export * from
|
|
25
|
-
export * from
|
|
26
|
-
export * from
|
|
27
|
-
export * from
|
|
1
|
+
export { type ExtensionData } from './ComponentContext';
|
|
2
|
+
export * from './ConfigurableLink';
|
|
3
|
+
export * from './Extension';
|
|
4
|
+
export * from './ExtensionSlot';
|
|
5
|
+
export * from './UserHasAccess';
|
|
6
|
+
export * from './getLifecycle';
|
|
7
|
+
export * from './useAbortController';
|
|
8
|
+
export * from './useAssignedExtensions';
|
|
9
|
+
export * from './useAssignedExtensionIds';
|
|
10
|
+
export * from './useBodyScrollLock';
|
|
11
|
+
export * from './useConfig';
|
|
12
|
+
export * from './useConnectedExtensions';
|
|
13
|
+
export * from './useConnectivity';
|
|
14
|
+
export * from './useDebounce';
|
|
15
|
+
export * from './useExtensionSlotMeta';
|
|
16
|
+
export * from './useExtensionStore';
|
|
17
|
+
export * from './useFeatureFlag';
|
|
18
|
+
export * from './useLayoutType';
|
|
19
|
+
export * from './useLocations';
|
|
20
|
+
export * from './useOnClickOutside';
|
|
21
|
+
export * from './useOpenmrsSWR';
|
|
22
|
+
export * from './usePatient';
|
|
23
|
+
export { useSession } from './useSession';
|
|
24
|
+
export * from './useStore';
|
|
25
|
+
export * from './useVisit';
|
|
26
|
+
export * from './useVisitTypes';
|
|
27
|
+
export * from './usePagination';
|
package/src/setup-tests.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
2
2
|
|
|
3
|
-
window.openmrsBase =
|
|
4
|
-
window.spaBase =
|
|
5
|
-
window.getOpenmrsSpaBase = () =>
|
|
3
|
+
window.openmrsBase = '/openmrs';
|
|
4
|
+
window.spaBase = '/spa';
|
|
5
|
+
window.getOpenmrsSpaBase = () => '/openmrs/spa/';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { renderHook, cleanup } from
|
|
2
|
-
import
|
|
3
|
-
import useAbortController from
|
|
1
|
+
import { renderHook, cleanup } from '@testing-library/react';
|
|
2
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
3
|
+
import useAbortController from './useAbortController';
|
|
4
4
|
|
|
5
|
-
describe(
|
|
5
|
+
describe('useAbortController', () => {
|
|
6
6
|
afterEach(cleanup);
|
|
7
7
|
|
|
8
|
-
it(
|
|
8
|
+
it('returns an AbortController', () => {
|
|
9
9
|
const { result } = renderHook(() => useAbortController());
|
|
10
10
|
expect(result.current).not.toBeNull();
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
it(
|
|
13
|
+
it('returns a consistent AbortController across re-renders', () => {
|
|
14
14
|
const { result, rerender } = renderHook(() => useAbortController());
|
|
15
15
|
const firstAc = result.current;
|
|
16
16
|
|
|
@@ -19,7 +19,7 @@ describe("useAbortController", () => {
|
|
|
19
19
|
expect(result.current).toBe(firstAc);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
it(
|
|
22
|
+
it('returns a new AbortController after the previous controller has been aborted', () => {
|
|
23
23
|
const { result, rerender } = renderHook(() => useAbortController());
|
|
24
24
|
const firstAc = result.current;
|
|
25
25
|
|
|
@@ -30,7 +30,7 @@ describe("useAbortController", () => {
|
|
|
30
30
|
expect(result.current).not.toBe(firstAc);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
it(
|
|
33
|
+
it('aborts the AbortController when the component is unmounted', () => {
|
|
34
34
|
const { result, unmount } = renderHook(() => useAbortController());
|
|
35
35
|
|
|
36
36
|
expect(result.current.signal.aborted).toBe(false);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @module @category Extension */
|
|
2
|
-
import { useEffect, useState } from
|
|
3
|
-
import { getExtensionStore } from
|
|
4
|
-
import isEqual from
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { getExtensionStore } from '@openmrs/esm-extensions';
|
|
4
|
+
import isEqual from 'lodash-es/isEqual';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Gets the assigned extension ids for a given extension slot name.
|
|
@@ -15,8 +15,7 @@ export function useAssignedExtensionIds(slotName: string) {
|
|
|
15
15
|
|
|
16
16
|
useEffect(() => {
|
|
17
17
|
return getExtensionStore().subscribe((state) => {
|
|
18
|
-
const newIds =
|
|
19
|
-
state.slots[slotName]?.assignedExtensions.map((e) => e.id) ?? [];
|
|
18
|
+
const newIds = state.slots[slotName]?.assignedExtensions.map((e) => e.id) ?? [];
|
|
20
19
|
if (!isEqual(newIds, ids)) {
|
|
21
20
|
setIds(newIds);
|
|
22
21
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/** @module @category Extension */
|
|
2
|
-
import { useEffect, useState } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
ExtensionStore,
|
|
6
|
-
getExtensionStore,
|
|
7
|
-
} from "@openmrs/esm-extensions";
|
|
8
|
-
import isEqual from "lodash-es/isEqual";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { AssignedExtension, ExtensionStore, getExtensionStore } from '@openmrs/esm-extensions';
|
|
4
|
+
import isEqual from 'lodash-es/isEqual';
|
|
9
5
|
|
|
10
6
|
/**
|
|
11
7
|
* Gets the assigned extensions for a given extension slot name.
|
package/src/useBodyScrollLock.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** @module @category UI */
|
|
2
|
-
import { useEffect } from
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
export function useBodyScrollLock(active: boolean) {
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
if (active) {
|
|
7
7
|
const original = window.getComputedStyle(document.body).overflow;
|
|
8
|
-
document.body.style.overflow =
|
|
8
|
+
document.body.style.overflow = 'hidden';
|
|
9
9
|
return () => {
|
|
10
10
|
document.body.style.overflow = original;
|
|
11
11
|
};
|
package/src/useConfig.test.tsx
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { render, cleanup, screen, waitFor, act } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, cleanup, screen, waitFor, act } from '@testing-library/react';
|
|
3
3
|
import {
|
|
4
4
|
defineConfigSchema,
|
|
5
5
|
temporaryConfigStore,
|
|
6
6
|
provide,
|
|
7
7
|
configInternalStore,
|
|
8
8
|
ConfigInternalStore,
|
|
9
|
-
} from
|
|
10
|
-
import { MockedStore } from
|
|
11
|
-
import { useConfig } from
|
|
12
|
-
import { ComponentContext } from
|
|
9
|
+
} from '@openmrs/esm-config';
|
|
10
|
+
import { MockedStore } from '../__mocks__/openmrs-esm-state.mock';
|
|
11
|
+
import { useConfig } from './useConfig';
|
|
12
|
+
import { ComponentContext } from './ComponentContext';
|
|
13
13
|
|
|
14
|
-
const mockConfigInternalStore =
|
|
15
|
-
configInternalStore as MockedStore<ConfigInternalStore>;
|
|
14
|
+
const mockConfigInternalStore = configInternalStore as MockedStore<ConfigInternalStore>;
|
|
16
15
|
|
|
17
16
|
function RenderConfig(props) {
|
|
18
17
|
const config = useConfig();
|
|
@@ -34,87 +33,83 @@ describe(`useConfig in root context`, () => {
|
|
|
34
33
|
afterEach(clearConfig);
|
|
35
34
|
|
|
36
35
|
it(`can return config as a react hook`, async () => {
|
|
37
|
-
defineConfigSchema(
|
|
36
|
+
defineConfigSchema('foo-module', {
|
|
38
37
|
thing: {
|
|
39
|
-
_default:
|
|
38
|
+
_default: 'The first thing',
|
|
40
39
|
},
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
render(
|
|
44
43
|
<React.Suspense fallback={<div>Suspense!</div>}>
|
|
45
|
-
<ComponentContext.Provider value={{ moduleName:
|
|
44
|
+
<ComponentContext.Provider value={{ moduleName: 'foo-module' }}>
|
|
46
45
|
<RenderConfig configKey="thing" />
|
|
47
46
|
</ComponentContext.Provider>
|
|
48
|
-
</React.Suspense
|
|
47
|
+
</React.Suspense>,
|
|
49
48
|
);
|
|
50
49
|
|
|
51
|
-
await waitFor(() =>
|
|
52
|
-
expect(screen.findByText("The first thing")).toBeTruthy()
|
|
53
|
-
);
|
|
50
|
+
await waitFor(() => expect(screen.findByText('The first thing')).toBeTruthy());
|
|
54
51
|
});
|
|
55
52
|
|
|
56
53
|
it(`can handle multiple calls to useConfig from different modules`, async () => {
|
|
57
|
-
defineConfigSchema(
|
|
54
|
+
defineConfigSchema('foo-module', {
|
|
58
55
|
thing: {
|
|
59
|
-
_default:
|
|
56
|
+
_default: 'foo thing',
|
|
60
57
|
},
|
|
61
58
|
});
|
|
62
59
|
|
|
63
|
-
defineConfigSchema(
|
|
60
|
+
defineConfigSchema('bar-module', {
|
|
64
61
|
thing: {
|
|
65
|
-
_default:
|
|
62
|
+
_default: 'bar thing',
|
|
66
63
|
},
|
|
67
64
|
});
|
|
68
65
|
|
|
69
66
|
render(
|
|
70
67
|
<React.Suspense fallback={<div>Suspense!</div>}>
|
|
71
|
-
<ComponentContext.Provider value={{ moduleName:
|
|
68
|
+
<ComponentContext.Provider value={{ moduleName: 'foo-module' }}>
|
|
72
69
|
<RenderConfig configKey="thing" />
|
|
73
70
|
</ComponentContext.Provider>
|
|
74
|
-
</React.Suspense
|
|
71
|
+
</React.Suspense>,
|
|
75
72
|
);
|
|
76
73
|
|
|
77
|
-
await waitFor(() => expect(screen.findByText(
|
|
74
|
+
await waitFor(() => expect(screen.findByText('foo thing')).toBeTruthy());
|
|
78
75
|
|
|
79
76
|
await cleanup();
|
|
80
77
|
|
|
81
78
|
render(
|
|
82
79
|
<React.Suspense fallback={<div>Suspense!</div>}>
|
|
83
|
-
<ComponentContext.Provider value={{ moduleName:
|
|
80
|
+
<ComponentContext.Provider value={{ moduleName: 'bar-module' }}>
|
|
84
81
|
<RenderConfig configKey="thing" />
|
|
85
82
|
</ComponentContext.Provider>
|
|
86
|
-
</React.Suspense
|
|
83
|
+
</React.Suspense>,
|
|
87
84
|
);
|
|
88
85
|
|
|
89
|
-
await waitFor(() => expect(screen.findByText(
|
|
86
|
+
await waitFor(() => expect(screen.findByText('bar thing')).toBeTruthy());
|
|
90
87
|
});
|
|
91
88
|
|
|
92
|
-
it(
|
|
93
|
-
defineConfigSchema(
|
|
89
|
+
it('updates with a new value when the temporary config is updated', async () => {
|
|
90
|
+
defineConfigSchema('foo-module', {
|
|
94
91
|
thing: {
|
|
95
|
-
_default:
|
|
92
|
+
_default: 'The first thing',
|
|
96
93
|
},
|
|
97
94
|
});
|
|
98
95
|
|
|
99
96
|
render(
|
|
100
97
|
<React.Suspense fallback={<div>Suspense!</div>}>
|
|
101
|
-
<ComponentContext.Provider value={{ moduleName:
|
|
98
|
+
<ComponentContext.Provider value={{ moduleName: 'foo-module' }}>
|
|
102
99
|
<RenderConfig configKey="thing" />
|
|
103
100
|
</ComponentContext.Provider>
|
|
104
|
-
</React.Suspense
|
|
101
|
+
</React.Suspense>,
|
|
105
102
|
);
|
|
106
103
|
|
|
107
|
-
await waitFor(() =>
|
|
108
|
-
expect(screen.findByText("The first thing")).toBeTruthy()
|
|
109
|
-
);
|
|
104
|
+
await waitFor(() => expect(screen.findByText('The first thing')).toBeTruthy());
|
|
110
105
|
|
|
111
106
|
act(() =>
|
|
112
107
|
temporaryConfigStore.setState({
|
|
113
|
-
config: {
|
|
114
|
-
})
|
|
108
|
+
config: { 'foo-module': { thing: 'A new thing' } },
|
|
109
|
+
}),
|
|
115
110
|
);
|
|
116
111
|
|
|
117
|
-
await waitFor(() => expect(screen.findByText(
|
|
112
|
+
await waitFor(() => expect(screen.findByText('A new thing')).toBeTruthy());
|
|
118
113
|
});
|
|
119
114
|
});
|
|
120
115
|
|
|
@@ -123,9 +118,9 @@ describe(`useConfig in an extension`, () => {
|
|
|
123
118
|
afterEach(cleanup);
|
|
124
119
|
|
|
125
120
|
it(`can return extension config as a react hook`, async () => {
|
|
126
|
-
defineConfigSchema(
|
|
121
|
+
defineConfigSchema('ext-module', {
|
|
127
122
|
thing: {
|
|
128
|
-
_default:
|
|
123
|
+
_default: 'The basics',
|
|
129
124
|
},
|
|
130
125
|
});
|
|
131
126
|
|
|
@@ -133,32 +128,32 @@ describe(`useConfig in an extension`, () => {
|
|
|
133
128
|
<React.Suspense fallback={<div>Suspense!</div>}>
|
|
134
129
|
<ComponentContext.Provider
|
|
135
130
|
value={{
|
|
136
|
-
moduleName:
|
|
131
|
+
moduleName: 'ext-module',
|
|
137
132
|
extension: {
|
|
138
|
-
extensionSlotName:
|
|
139
|
-
extensionSlotModuleName:
|
|
140
|
-
extensionId:
|
|
133
|
+
extensionSlotName: 'fooSlot',
|
|
134
|
+
extensionSlotModuleName: 'slot-mod',
|
|
135
|
+
extensionId: 'barExt#id1',
|
|
141
136
|
},
|
|
142
137
|
}}
|
|
143
138
|
>
|
|
144
139
|
<RenderConfig configKey="thing" />
|
|
145
140
|
</ComponentContext.Provider>
|
|
146
|
-
</React.Suspense
|
|
141
|
+
</React.Suspense>,
|
|
147
142
|
);
|
|
148
143
|
|
|
149
|
-
await waitFor(() => expect(screen.findByText(
|
|
144
|
+
await waitFor(() => expect(screen.findByText('The basics')).toBeTruthy());
|
|
150
145
|
});
|
|
151
146
|
|
|
152
147
|
it(`can handle multiple extensions`, async () => {
|
|
153
|
-
defineConfigSchema(
|
|
148
|
+
defineConfigSchema('first-module', {
|
|
154
149
|
thing: {
|
|
155
|
-
_default:
|
|
150
|
+
_default: 'first thing',
|
|
156
151
|
},
|
|
157
152
|
});
|
|
158
153
|
|
|
159
|
-
defineConfigSchema(
|
|
154
|
+
defineConfigSchema('second-module', {
|
|
160
155
|
thing: {
|
|
161
|
-
_default:
|
|
156
|
+
_default: 'second thing',
|
|
162
157
|
},
|
|
163
158
|
});
|
|
164
159
|
|
|
@@ -166,11 +161,11 @@ describe(`useConfig in an extension`, () => {
|
|
|
166
161
|
<React.Suspense fallback={<div>Suspense!</div>}>
|
|
167
162
|
<ComponentContext.Provider
|
|
168
163
|
value={{
|
|
169
|
-
moduleName:
|
|
164
|
+
moduleName: 'first-module',
|
|
170
165
|
extension: {
|
|
171
|
-
extensionSlotName:
|
|
172
|
-
extensionSlotModuleName:
|
|
173
|
-
extensionId:
|
|
166
|
+
extensionSlotName: 'fooSlot',
|
|
167
|
+
extensionSlotModuleName: 'slot-mod',
|
|
168
|
+
extensionId: 'fooExt#id1',
|
|
174
169
|
},
|
|
175
170
|
}}
|
|
176
171
|
>
|
|
@@ -178,36 +173,36 @@ describe(`useConfig in an extension`, () => {
|
|
|
178
173
|
</ComponentContext.Provider>
|
|
179
174
|
<ComponentContext.Provider
|
|
180
175
|
value={{
|
|
181
|
-
moduleName:
|
|
176
|
+
moduleName: 'second-module',
|
|
182
177
|
extension: {
|
|
183
|
-
extensionSlotName:
|
|
184
|
-
extensionSlotModuleName:
|
|
185
|
-
extensionId:
|
|
178
|
+
extensionSlotName: 'fooSlot',
|
|
179
|
+
extensionSlotModuleName: 'slot-mod',
|
|
180
|
+
extensionId: 'barExt',
|
|
186
181
|
},
|
|
187
182
|
}}
|
|
188
183
|
>
|
|
189
184
|
<RenderConfig configKey="thing" />
|
|
190
185
|
</ComponentContext.Provider>
|
|
191
|
-
</React.Suspense
|
|
186
|
+
</React.Suspense>,
|
|
192
187
|
);
|
|
193
188
|
|
|
194
|
-
await waitFor(() => expect(screen.findByText(
|
|
195
|
-
await waitFor(() => expect(screen.findByText(
|
|
189
|
+
await waitFor(() => expect(screen.findByText('first thing')).toBeTruthy());
|
|
190
|
+
await waitFor(() => expect(screen.findByText('second thing')).toBeTruthy());
|
|
196
191
|
});
|
|
197
192
|
|
|
198
|
-
it(
|
|
199
|
-
defineConfigSchema(
|
|
193
|
+
it('can handle multiple extension slots', async () => {
|
|
194
|
+
defineConfigSchema('extension-module', {
|
|
200
195
|
thing: {
|
|
201
|
-
_default:
|
|
196
|
+
_default: 'old extension thing',
|
|
202
197
|
},
|
|
203
198
|
});
|
|
204
199
|
|
|
205
200
|
provide({
|
|
206
|
-
|
|
201
|
+
'slot-2-module': {
|
|
207
202
|
extensions: {
|
|
208
203
|
slot2: {
|
|
209
204
|
configure: {
|
|
210
|
-
fooExt: { thing:
|
|
205
|
+
fooExt: { thing: 'a different thing' },
|
|
211
206
|
},
|
|
212
207
|
},
|
|
213
208
|
},
|
|
@@ -218,11 +213,11 @@ describe(`useConfig in an extension`, () => {
|
|
|
218
213
|
<React.Suspense fallback={<div>Suspense!</div>}>
|
|
219
214
|
<ComponentContext.Provider
|
|
220
215
|
value={{
|
|
221
|
-
moduleName:
|
|
216
|
+
moduleName: 'extension-module',
|
|
222
217
|
extension: {
|
|
223
|
-
extensionSlotName:
|
|
224
|
-
extensionSlotModuleName:
|
|
225
|
-
extensionId:
|
|
218
|
+
extensionSlotName: 'slot1',
|
|
219
|
+
extensionSlotModuleName: 'slot-1-module',
|
|
220
|
+
extensionId: 'fooExt',
|
|
226
221
|
},
|
|
227
222
|
}}
|
|
228
223
|
>
|
|
@@ -230,31 +225,27 @@ describe(`useConfig in an extension`, () => {
|
|
|
230
225
|
</ComponentContext.Provider>
|
|
231
226
|
<ComponentContext.Provider
|
|
232
227
|
value={{
|
|
233
|
-
moduleName:
|
|
228
|
+
moduleName: 'extension-module',
|
|
234
229
|
extension: {
|
|
235
|
-
extensionSlotName:
|
|
236
|
-
extensionSlotModuleName:
|
|
237
|
-
extensionId:
|
|
230
|
+
extensionSlotName: 'slot2',
|
|
231
|
+
extensionSlotModuleName: 'slot-2-module',
|
|
232
|
+
extensionId: 'fooExt',
|
|
238
233
|
},
|
|
239
234
|
}}
|
|
240
235
|
>
|
|
241
236
|
<RenderConfig configKey="thing" />
|
|
242
237
|
</ComponentContext.Provider>
|
|
243
|
-
</React.Suspense
|
|
238
|
+
</React.Suspense>,
|
|
244
239
|
);
|
|
245
240
|
|
|
246
|
-
await waitFor(() =>
|
|
247
|
-
|
|
248
|
-
);
|
|
249
|
-
await waitFor(() =>
|
|
250
|
-
expect(screen.findByText("a different thing")).toBeTruthy()
|
|
251
|
-
);
|
|
241
|
+
await waitFor(() => expect(screen.findByText('old extension thing')).toBeTruthy());
|
|
242
|
+
await waitFor(() => expect(screen.findByText('a different thing')).toBeTruthy());
|
|
252
243
|
});
|
|
253
244
|
|
|
254
|
-
it(
|
|
255
|
-
defineConfigSchema(
|
|
245
|
+
it('updates with a new value when the temporary config is updated', async () => {
|
|
246
|
+
defineConfigSchema('ext-module', {
|
|
256
247
|
thing: {
|
|
257
|
-
_default:
|
|
248
|
+
_default: 'The first thing',
|
|
258
249
|
},
|
|
259
250
|
});
|
|
260
251
|
|
|
@@ -262,35 +253,33 @@ describe(`useConfig in an extension`, () => {
|
|
|
262
253
|
<React.Suspense fallback={<div>Suspense!</div>}>
|
|
263
254
|
<ComponentContext.Provider
|
|
264
255
|
value={{
|
|
265
|
-
moduleName:
|
|
256
|
+
moduleName: 'ext-module',
|
|
266
257
|
extension: {
|
|
267
|
-
extensionSlotName:
|
|
268
|
-
extensionSlotModuleName:
|
|
269
|
-
extensionId:
|
|
258
|
+
extensionSlotName: 'fooSlot',
|
|
259
|
+
extensionSlotModuleName: 'slot-module',
|
|
260
|
+
extensionId: 'barExt#id1',
|
|
270
261
|
},
|
|
271
262
|
}}
|
|
272
263
|
>
|
|
273
264
|
<RenderConfig configKey="thing" />
|
|
274
265
|
</ComponentContext.Provider>
|
|
275
|
-
</React.Suspense
|
|
266
|
+
</React.Suspense>,
|
|
276
267
|
);
|
|
277
268
|
|
|
278
|
-
await waitFor(() =>
|
|
279
|
-
expect(screen.findByText("The first thing")).toBeTruthy()
|
|
280
|
-
);
|
|
269
|
+
await waitFor(() => expect(screen.findByText('The first thing')).toBeTruthy());
|
|
281
270
|
|
|
282
|
-
const newConfig = {
|
|
271
|
+
const newConfig = { 'ext-module': { thing: 'A new thing' } };
|
|
283
272
|
act(() => temporaryConfigStore.setState({ config: newConfig }));
|
|
284
273
|
|
|
285
|
-
await waitFor(() => expect(screen.findByText(
|
|
274
|
+
await waitFor(() => expect(screen.findByText('A new thing')).toBeTruthy());
|
|
286
275
|
|
|
287
276
|
const newConfig2 = {
|
|
288
|
-
|
|
277
|
+
'slot-module': {
|
|
289
278
|
extensions: {
|
|
290
279
|
fooSlot: {
|
|
291
280
|
configure: {
|
|
292
|
-
|
|
293
|
-
thing:
|
|
281
|
+
'barExt#id1': {
|
|
282
|
+
thing: 'Yet another thing',
|
|
294
283
|
},
|
|
295
284
|
},
|
|
296
285
|
},
|
|
@@ -299,21 +288,19 @@ describe(`useConfig in an extension`, () => {
|
|
|
299
288
|
};
|
|
300
289
|
act(() => temporaryConfigStore.setState({ config: newConfig2 }));
|
|
301
290
|
|
|
302
|
-
await waitFor(() =>
|
|
303
|
-
expect(screen.findByText("Yet another thing")).toBeTruthy()
|
|
304
|
-
);
|
|
291
|
+
await waitFor(() => expect(screen.findByText('Yet another thing')).toBeTruthy());
|
|
305
292
|
});
|
|
306
293
|
|
|
307
294
|
it("can optionally load an external module's configuration", async () => {
|
|
308
|
-
defineConfigSchema(
|
|
295
|
+
defineConfigSchema('first-module', {
|
|
309
296
|
thing: {
|
|
310
|
-
_default:
|
|
297
|
+
_default: 'first thing',
|
|
311
298
|
},
|
|
312
299
|
});
|
|
313
300
|
|
|
314
|
-
defineConfigSchema(
|
|
301
|
+
defineConfigSchema('second-module', {
|
|
315
302
|
thing: {
|
|
316
|
-
_default:
|
|
303
|
+
_default: 'second thing',
|
|
317
304
|
},
|
|
318
305
|
});
|
|
319
306
|
|
|
@@ -321,22 +308,19 @@ describe(`useConfig in an extension`, () => {
|
|
|
321
308
|
<React.Suspense fallback={<div>Suspense!</div>}>
|
|
322
309
|
<ComponentContext.Provider
|
|
323
310
|
value={{
|
|
324
|
-
moduleName:
|
|
311
|
+
moduleName: 'first-module',
|
|
325
312
|
extension: {
|
|
326
|
-
extensionSlotName:
|
|
327
|
-
extensionSlotModuleName:
|
|
328
|
-
extensionId:
|
|
313
|
+
extensionSlotName: 'fooSlot',
|
|
314
|
+
extensionSlotModuleName: 'slot-mod',
|
|
315
|
+
extensionId: 'fooExt#id1',
|
|
329
316
|
},
|
|
330
317
|
}}
|
|
331
318
|
>
|
|
332
|
-
<RenderExternalConfig
|
|
333
|
-
externalModuleName="second-module"
|
|
334
|
-
configKey="thing"
|
|
335
|
-
/>
|
|
319
|
+
<RenderExternalConfig externalModuleName="second-module" configKey="thing" />
|
|
336
320
|
</ComponentContext.Provider>
|
|
337
|
-
</React.Suspense
|
|
321
|
+
</React.Suspense>,
|
|
338
322
|
);
|
|
339
323
|
|
|
340
|
-
await waitFor(() => expect(screen.findByText(
|
|
324
|
+
await waitFor(() => expect(screen.findByText('second thing')).toBeTruthy());
|
|
341
325
|
});
|
|
342
326
|
});
|