diff --git a/packages/framework/esm-framework/src/integration-tests/extension-config.test.tsx b/packages/framework/esm-framework/src/integration-tests/extension-config.test.tsx index e9f029b83..27f62e547 100644 --- a/packages/framework/esm-framework/src/integration-tests/extension-config.test.tsx +++ b/packages/framework/esm-framework/src/integration-tests/extension-config.test.tsx @@ -1,4 +1,7 @@ import React from "react"; +import { act, render, screen, waitFor } from "@testing-library/react"; +import { Person } from "@openmrs/esm-api"; +import { mockSessionStore } from "../../mock"; import { attach, registerExtension, @@ -19,9 +22,6 @@ import { configInternalStore, getExtensionSlotsConfigStore, } from "../../../esm-config/src"; -import { act, render, screen, waitFor } from "@testing-library/react"; -import { Person } from "@openmrs/esm-api"; -import { mockSessionStore } from "../../mock"; jest.mock("@openmrs/esm-api", () => { const original = jest.requireActual("@openmrs/esm-api"); @@ -71,10 +71,13 @@ describe("Interaction between configuration and extension systems", () => { const slot = screen.getByTestId("slot"); const extensions = slot.childNodes; - expect(extensions[0]).toHaveTextContent("Betty"); - expect(extensions[1]).toHaveTextContent("Wilma"); - expect(extensions[2]).toHaveTextContent("Barney"); - expect(screen.queryByText("Fred")).not.toBeInTheDocument(); + + await waitFor(() => { + expect(extensions[0]).toHaveTextContent("Betty"); + expect(extensions[1]).toHaveTextContent("Wilma"); + expect(extensions[2]).toHaveTextContent("Barney"); + expect(screen.queryByText("Fred")).not.toBeInTheDocument(); + }); }); test("Extensions should recieve config from module and from 'configure' key", async () => { @@ -114,9 +117,12 @@ describe("Interaction between configuration and extension systems", () => { await screen.findAllByText(/.*Pebbles.*/); const flintstonePebbles = screen.getByTestId("flintstone-slot"); - expect(flintstonePebbles).toHaveTextContent(/Pebbles:.*Springfield/); const futurePebbles = screen.getByTestId("future-slot"); - expect(futurePebbles).toHaveTextContent(/Pebbles:.*New New York/); + + await waitFor(() => { + expect(flintstonePebbles).toHaveTextContent(/Pebbles:.*Springfield/); + expect(futurePebbles).toHaveTextContent(/Pebbles:.*New New York/); + }); }); test("Should be possible to attach the same extension twice with different configurations", async () => { @@ -157,8 +163,11 @@ describe("Interaction between configuration and extension systems", () => { await screen.findAllByText(/.*Dino.*/); const slot = screen.getByTestId("flintstone-slot"); - expect(slot.firstChild).toHaveTextContent(/Dino/); - expect(slot.lastChild).toHaveTextContent(/Baby Puss/); + + await waitFor(() => { + expect(slot.firstChild).toHaveTextContent(/Dino/); + expect(slot.lastChild).toHaveTextContent(/Baby Puss/); + }); }); test("Slot config should update with temporary config", async () => { @@ -189,7 +198,9 @@ describe("Interaction between configuration and extension systems", () => { }); }); - expect(screen.queryByText("Pearl")).not.toBeInTheDocument(); + await waitFor(() => + expect(screen.queryByText("Pearl")).not.toBeInTheDocument() + ); }); test("Extension config should update with temporary config", async () => { @@ -226,10 +237,10 @@ describe("Interaction between configuration and extension systems", () => { }); }); - expect(screen.queryByText("green")).not.toBeInTheDocument(); - waitFor(() => - expect(screen.getByTestId("slot")).toHaveTextContent(/black/) - ); + await waitFor(() => { + expect(screen.queryByText("green")).not.toBeInTheDocument(); + expect(screen.getByTestId("slot")).toHaveTextContent(/black/); + }); }); test("Extension config should be available in extension store", async () => { @@ -441,12 +452,14 @@ describe("Interaction between configuration and extension systems", () => { render(); - await waitFor(() => expect(screen.getByTestId(/slot/)).toBeInTheDocument()); - expect(screen.getByTestId("slot").firstChild).toHaveAttribute( - "data-extension-id", - "Wilma" - ); - expect(screen.queryAllByText(/\bSchmoo\b/)).toHaveLength(0); + await waitFor(() => { + expect(screen.getByTestId(/slot/)).toBeInTheDocument(); + expect(screen.getByTestId("slot").firstChild).toHaveAttribute( + "data-extension-id", + "Wilma" + ); + expect(screen.queryAllByText(/\bSchmoo\b/)).toHaveLength(0); + }); }); });