From d65e9700f3ab2a2764056c7c9fe0b83485408423 Mon Sep 17 00:00:00 2001 From: "Hung-Han (Henry) Chen" Date: Tue, 5 Oct 2021 09:02:54 +0300 Subject: [PATCH] Add addOnRunHook return false test Signed-off-by: Hung-Han (Henry) Chen --- .../components/+catalog/catalog.test.tsx | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/renderer/components/+catalog/catalog.test.tsx b/src/renderer/components/+catalog/catalog.test.tsx index b10a71d95b..cff26d9ab9 100644 --- a/src/renderer/components/+catalog/catalog.test.tsx +++ b/src/renderer/components/+catalog/catalog.test.tsx @@ -167,7 +167,7 @@ describe("", () => { setTimeout(() => { expect(onRun).toHaveBeenCalled(); done(); - }, 800); + }, 500); return true; } @@ -184,4 +184,48 @@ describe("", () => { userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon")); }); + + it("addOnRunHook return false => onRun wont be triggered", (done) => { + const onRun = jest.fn(); + const catalogEntityItem = new CatalogEntityItem({ + ...catalogEntity, + ...catalogEntityItemMethods, + onRun, + }); + + const catalogCategoryRegistry = new CatalogCategoryRegistry(); + const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry); + const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry); + + // mock as if there is a selected item > the detail panel opens + jest + .spyOn(catalogEntityStore, "selectedItem", "get") + .mockImplementation(() => { + return catalogEntityItem; + }); + + const onRunDisposer = catalogEntityRegistry.addOnRunHook( + catalogEntityUid, + () => { + onRunDisposer?.(); + setTimeout(() => { + expect(onRun).not.toHaveBeenCalled(); + done(); + }, 500); + + return false; + } + ); + + render( + + ); + + userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon")); + }); });