From c264d5f1e244cd7fc0823324e362c38de40146b9 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 5 Oct 2021 11:53:23 -0400 Subject: [PATCH] Fix tests Signed-off-by: Sebastian Malton --- src/renderer/api/catalog-entity-registry.ts | 4 ++ .../components/+catalog/catalog.test.tsx | 52 +++++-------------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/renderer/api/catalog-entity-registry.ts b/src/renderer/api/catalog-entity-registry.ts index 940bbd8463..f70599791d 100644 --- a/src/renderer/api/catalog-entity-registry.ts +++ b/src/renderer/api/catalog-entity-registry.ts @@ -185,6 +185,8 @@ export class CatalogEntityRegistry { * @returns A function to remove that hook */ addOnBeforeRun(entityOrId: CatalogEntity | CatalogEntityUid, onBeforeRun: CatalogEntityOnBeforeRun): Disposer { + logger.debug(`[CATALOG-ENTITY-REGISTRY]: adding onBeforeRun to ${entityOrId}`); + const id = typeof entityOrId === "string" ? entityOrId : entityOrId.getId(); @@ -202,6 +204,8 @@ export class CatalogEntityRegistry { * @returns Whether the entities `onRun` method should be executed */ async onBeforeRun(entity: CatalogEntity): Promise { + logger.debug(`[CATALOG-ENTITY-REGISTRY]: run onBeforeRun on ${entity.getId()}`); + const hooks = this.onBeforeRunHooks.get(entity.getId()); if (!hooks) { diff --git a/src/renderer/components/+catalog/catalog.test.tsx b/src/renderer/components/+catalog/catalog.test.tsx index 8405152ed5..763398d1eb 100644 --- a/src/renderer/components/+catalog/catalog.test.tsx +++ b/src/renderer/components/+catalog/catalog.test.tsx @@ -84,8 +84,8 @@ describe("", () => { spec: {}, }; const catalogEntityItemMethods = { - getId: () => "", - getName: () => "", + getId: () => catalogEntity.metadata.uid, + getName: () => catalogEntity.metadata.name, onContextMenuOpen: () => {}, onSettingsOpen: () => {}, onRun: () => {}, @@ -127,19 +127,11 @@ describe("", () => { // mock as if there is a selected item > the detail panel opens jest .spyOn(catalogEntityStore, "selectedItem", "get") - .mockImplementation(() => { - return catalogEntityItem; - }); + .mockImplementation(() => catalogEntityItem); - let hookGetCalled = false; - - const onRunDisposer = catalogEntityRegistry.addOnBeforeRun( + catalogEntityRegistry.addOnBeforeRun( catalogEntityUid, (entity) => { - hookGetCalled = true; - expect(hookGetCalled).toBe(true); - - onRunDisposer?.(); expect(entity).toMatchInlineSnapshot(` Object { "apiVersion": "api", @@ -200,14 +192,11 @@ describe("", () => { // mock as if there is a selected item > the detail panel opens jest .spyOn(catalogEntityStore, "selectedItem", "get") - .mockImplementation(() => { - return catalogEntityItem; - }); + .mockImplementation(() => catalogEntityItem); - const onRunDisposer = catalogEntityRegistry.addOnBeforeRun( + catalogEntityRegistry.addOnBeforeRun( catalogEntityUid, () => { - onRunDisposer?.(); setTimeout(() => { expect(onRun).not.toHaveBeenCalled(); done(); @@ -244,14 +233,11 @@ describe("", () => { // mock as if there is a selected item > the detail panel opens jest .spyOn(catalogEntityStore, "selectedItem", "get") - .mockImplementation(() => { - return catalogEntityItem; - }); + .mockImplementation(() => catalogEntityItem); - const onRunDisposer = catalogEntityRegistry.addOnBeforeRun( + catalogEntityRegistry.addOnBeforeRun( catalogEntityUid, () => { - onRunDisposer?.(); setTimeout(() => { expect(onRun).not.toHaveBeenCalled(); done(); @@ -293,15 +279,11 @@ describe("", () => { // mock as if there is a selected item > the detail panel opens jest .spyOn(catalogEntityStore, "selectedItem", "get") - .mockImplementation(() => { - return catalogEntityItem; - }); + .mockImplementation(() => catalogEntityItem); - const onRunDisposer = catalogEntityRegistry.addOnBeforeRun( + catalogEntityRegistry.addOnBeforeRun( catalogEntityUid, async () => { - onRunDisposer?.(); - return true; } ); @@ -336,14 +318,11 @@ describe("", () => { // mock as if there is a selected item > the detail panel opens jest .spyOn(catalogEntityStore, "selectedItem", "get") - .mockImplementation(() => { - return catalogEntityItem; - }); + .mockImplementation(() => catalogEntityItem); - const onRunDisposer = catalogEntityRegistry.addOnBeforeRun( + catalogEntityRegistry.addOnBeforeRun( catalogEntityUid, async () => { - onRunDisposer?.(); expect(onRunTriggered).toBeFalsy(); setTimeout(() => { @@ -382,14 +361,11 @@ describe("", () => { // mock as if there is a selected item > the detail panel opens jest .spyOn(catalogEntityStore, "selectedItem", "get") - .mockImplementation(() => { - return catalogEntityItem; - }); + .mockImplementation(() => catalogEntityItem); - const onRunDisposer = catalogEntityRegistry.addOnBeforeRun( + catalogEntityRegistry.addOnBeforeRun( catalogEntityUid, async () => { - onRunDisposer?.(); setTimeout(() => { expect(onRun).not.toHaveBeenCalled(); done();