From 960e266173a9800205675172dc0a683334e70a50 Mon Sep 17 00:00:00 2001 From: Alexandre Neuwald CTW Date: Wed, 8 May 2024 15:27:20 +0100 Subject: [PATCH] add unit tests --- .../src/panels/createSyncRoot.test.tsx | 39 +++++++++++++++++++ packages/studio-web/src/index.tsx | 4 ++ 2 files changed, 43 insertions(+) create mode 100644 packages/studio-base/src/panels/createSyncRoot.test.tsx diff --git a/packages/studio-base/src/panels/createSyncRoot.test.tsx b/packages/studio-base/src/panels/createSyncRoot.test.tsx new file mode 100644 index 0000000000..6bde2939c4 --- /dev/null +++ b/packages/studio-base/src/panels/createSyncRoot.test.tsx @@ -0,0 +1,39 @@ +/** @jest-environment jsdom */ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/ +import { screen } from "@testing-library/react"; +import { act } from "react-dom/test-utils"; + +import { createSyncRoot } from "@foxglove/studio-base/panels/createSyncRoot"; + +describe("createSyncRoot", () => { + it("should mount the component", async () => { + const textTest = "Mount Component Test"; + const TestComponent = () =>
{textTest}
; + + const container = document.createElement("div"); + document.body.appendChild(container); + + act(() => { + createSyncRoot(, container); + }); + + expect(await screen.findByText(textTest)).toBeDefined(); + }); + + it("should unmount the component", async () => { + const textTest = "Unmount Component Test"; + const TestComponent = () =>
{textTest}
; + + const container = document.createElement("div"); + document.body.appendChild(container); + + act(() => { + const unmountCb = createSyncRoot(, container); + unmountCb(); + }); + + expect(JSON.stringify(await screen.findByText(textTest))).toBe("{}"); + }); +}); diff --git a/packages/studio-web/src/index.tsx b/packages/studio-web/src/index.tsx index f8a47eeb50..11e43ec875 100644 --- a/packages/studio-web/src/index.tsx +++ b/packages/studio-web/src/index.tsx @@ -93,4 +93,8 @@ export async function main(getParams: () => Promise = async () => ({ , ); + + setTimeout(() => { + root.unmount(); + }, 5_000); }