@openmrs/esm-framework 3.2.1-pre.1044 → 3.2.1-pre.1048

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.
@@ -3,6 +3,7 @@ import {
3
3
  attach,
4
4
  registerExtension,
5
5
  updateInternalExtensionStore,
6
+ getExtensionInternalStore,
6
7
  getExtensionStore,
7
8
  } from "../../../esm-extensions";
8
9
  import {
@@ -10,6 +11,7 @@ import {
10
11
  getSyncLifecycle,
11
12
  openmrsComponentDecorator,
12
13
  useConfig,
14
+ useExtensionStore,
13
15
  } from "../../../esm-react-utils/src";
14
16
  import {
15
17
  defineConfigSchema,
@@ -65,19 +67,19 @@ describe("Interaction between configuration and extension systems", () => {
65
67
  });
66
68
 
67
69
  test("Extensions should recieve config from module and from 'configure' key", async () => {
68
- registerSimpleExtension("Wilma", "esm-flintstone", true);
70
+ registerSimpleExtension("Pebbles", "esm-flintstone", true);
69
71
  defineConfigSchema("esm-flintstone", {
70
72
  town: { _type: Type.String, _default: "Bedrock" },
71
73
  });
72
- attach("Flintstone slot", "Wilma");
73
- attach("Future slot", "Wilma");
74
+ attach("Flintstone slot", "Pebbles");
75
+ attach("Future slot", "Pebbles");
74
76
  provide({
75
77
  "esm-flintstone": {
76
78
  town: "Springfield",
77
79
  extensionSlots: {
78
80
  "Future slot": {
79
81
  configure: {
80
- Wilma: {
82
+ Pebbles: {
81
83
  town: "New New York",
82
84
  },
83
85
  },
@@ -102,11 +104,11 @@ describe("Interaction between configuration and extension systems", () => {
102
104
  </>
103
105
  ));
104
106
  render(<App />);
105
- await screen.findAllByText(/.*Wilma.*/);
106
- const flintstoneWilma = screen.getByTestId("flintstone-slot");
107
- expect(flintstoneWilma).toHaveTextContent(/Wilma:.*Springfield/);
108
- const futureWilma = screen.getByTestId("future-slot");
109
- expect(futureWilma).toHaveTextContent(/Wilma:.*New New York/);
107
+ await screen.findAllByText(/.*Pebbles.*/);
108
+ const flintstonePebbles = screen.getByTestId("flintstone-slot");
109
+ expect(flintstonePebbles).toHaveTextContent(/Pebbles:.*Springfield/);
110
+ const futurePebbles = screen.getByTestId("future-slot");
111
+ expect(futurePebbles).toHaveTextContent(/Pebbles:.*New New York/);
110
112
  });
111
113
 
112
114
  test("Should be possible to attach the same extension twice with different configurations", async () => {
@@ -210,6 +212,47 @@ describe("Interaction between configuration and extension systems", () => {
210
212
  expect(screen.queryByText("green")).not.toBeInTheDocument();
211
213
  expect(screen.getByTestId("slot")).toHaveTextContent(/black/);
212
214
  });
215
+
216
+ test("Extension config should be available in extension store", async () => {
217
+ registerSimpleExtension("Bamm-Bamm", "esm-flintstone", false);
218
+ attach("A slot", "Bamm-Bamm");
219
+ defineConfigSchema("esm-flintstone", { clothes: { _default: "leopard" } });
220
+ function RootComponent() {
221
+ const store = useExtensionStore();
222
+ return (
223
+ <div>
224
+ <ExtensionSlot data-testid="slot" extensionSlotName="A slot" />
225
+ {store.slots["A slot"].assignedExtensions.map((e) => (
226
+ <div key={e.name}>{JSON.stringify(e.config)}</div>
227
+ ))}
228
+ </div>
229
+ );
230
+ }
231
+ const App = openmrsComponentDecorator({
232
+ moduleName: "esm-flintstone",
233
+ featureName: "The Flintstones",
234
+ disableTranslations: true,
235
+ })(RootComponent);
236
+ render(<App />);
237
+ await waitFor(() => expect(screen.getByTestId(/slot/)).toBeInTheDocument());
238
+ expect(screen.getByText(/clothes/)).toHaveTextContent(/leopard/);
239
+ act(() => {
240
+ temporaryConfigStore.setState({
241
+ config: {
242
+ "esm-flintstone": {
243
+ extensionSlots: {
244
+ "A slot": {
245
+ configure: {
246
+ "Bamm-Bamm": { clothes: "tiger" },
247
+ },
248
+ },
249
+ },
250
+ },
251
+ },
252
+ });
253
+ });
254
+ expect(screen.getByText(/clothes/)).toHaveTextContent(/tiger/);
255
+ });
213
256
  });
214
257
 
215
258
  function registerSimpleExtension(