1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-10-05 11:53:23 -04:00
parent 44a8824635
commit c264d5f1e2
2 changed files with 18 additions and 38 deletions

View File

@ -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<boolean> {
logger.debug(`[CATALOG-ENTITY-REGISTRY]: run onBeforeRun on ${entity.getId()}`);
const hooks = this.onBeforeRunHooks.get(entity.getId());
if (!hooks) {

View File

@ -84,8 +84,8 @@ describe("<Catalog />", () => {
spec: {},
};
const catalogEntityItemMethods = {
getId: () => "",
getName: () => "",
getId: () => catalogEntity.metadata.uid,
getName: () => catalogEntity.metadata.name,
onContextMenuOpen: () => {},
onSettingsOpen: () => {},
onRun: () => {},
@ -127,19 +127,11 @@ describe("<Catalog />", () => {
// 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("<Catalog />", () => {
// 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("<Catalog />", () => {
// 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("<Catalog />", () => {
// 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("<Catalog />", () => {
// 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("<Catalog />", () => {
// 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();