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:
parent
44a8824635
commit
c264d5f1e2
@ -185,6 +185,8 @@ export class CatalogEntityRegistry {
|
|||||||
* @returns A function to remove that hook
|
* @returns A function to remove that hook
|
||||||
*/
|
*/
|
||||||
addOnBeforeRun(entityOrId: CatalogEntity | CatalogEntityUid, onBeforeRun: CatalogEntityOnBeforeRun): Disposer {
|
addOnBeforeRun(entityOrId: CatalogEntity | CatalogEntityUid, onBeforeRun: CatalogEntityOnBeforeRun): Disposer {
|
||||||
|
logger.debug(`[CATALOG-ENTITY-REGISTRY]: adding onBeforeRun to ${entityOrId}`);
|
||||||
|
|
||||||
const id = typeof entityOrId === "string"
|
const id = typeof entityOrId === "string"
|
||||||
? entityOrId
|
? entityOrId
|
||||||
: entityOrId.getId();
|
: entityOrId.getId();
|
||||||
@ -202,6 +204,8 @@ export class CatalogEntityRegistry {
|
|||||||
* @returns Whether the entities `onRun` method should be executed
|
* @returns Whether the entities `onRun` method should be executed
|
||||||
*/
|
*/
|
||||||
async onBeforeRun(entity: CatalogEntity): Promise<boolean> {
|
async onBeforeRun(entity: CatalogEntity): Promise<boolean> {
|
||||||
|
logger.debug(`[CATALOG-ENTITY-REGISTRY]: run onBeforeRun on ${entity.getId()}`);
|
||||||
|
|
||||||
const hooks = this.onBeforeRunHooks.get(entity.getId());
|
const hooks = this.onBeforeRunHooks.get(entity.getId());
|
||||||
|
|
||||||
if (!hooks) {
|
if (!hooks) {
|
||||||
|
|||||||
@ -84,8 +84,8 @@ describe("<Catalog />", () => {
|
|||||||
spec: {},
|
spec: {},
|
||||||
};
|
};
|
||||||
const catalogEntityItemMethods = {
|
const catalogEntityItemMethods = {
|
||||||
getId: () => "",
|
getId: () => catalogEntity.metadata.uid,
|
||||||
getName: () => "",
|
getName: () => catalogEntity.metadata.name,
|
||||||
onContextMenuOpen: () => {},
|
onContextMenuOpen: () => {},
|
||||||
onSettingsOpen: () => {},
|
onSettingsOpen: () => {},
|
||||||
onRun: () => {},
|
onRun: () => {},
|
||||||
@ -127,19 +127,11 @@ describe("<Catalog />", () => {
|
|||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
.spyOn(catalogEntityStore, "selectedItem", "get")
|
.spyOn(catalogEntityStore, "selectedItem", "get")
|
||||||
.mockImplementation(() => {
|
.mockImplementation(() => catalogEntityItem);
|
||||||
return catalogEntityItem;
|
|
||||||
});
|
|
||||||
|
|
||||||
let hookGetCalled = false;
|
catalogEntityRegistry.addOnBeforeRun(
|
||||||
|
|
||||||
const onRunDisposer = catalogEntityRegistry.addOnBeforeRun(
|
|
||||||
catalogEntityUid,
|
catalogEntityUid,
|
||||||
(entity) => {
|
(entity) => {
|
||||||
hookGetCalled = true;
|
|
||||||
expect(hookGetCalled).toBe(true);
|
|
||||||
|
|
||||||
onRunDisposer?.();
|
|
||||||
expect(entity).toMatchInlineSnapshot(`
|
expect(entity).toMatchInlineSnapshot(`
|
||||||
Object {
|
Object {
|
||||||
"apiVersion": "api",
|
"apiVersion": "api",
|
||||||
@ -200,14 +192,11 @@ describe("<Catalog />", () => {
|
|||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
.spyOn(catalogEntityStore, "selectedItem", "get")
|
.spyOn(catalogEntityStore, "selectedItem", "get")
|
||||||
.mockImplementation(() => {
|
.mockImplementation(() => catalogEntityItem);
|
||||||
return catalogEntityItem;
|
|
||||||
});
|
|
||||||
|
|
||||||
const onRunDisposer = catalogEntityRegistry.addOnBeforeRun(
|
catalogEntityRegistry.addOnBeforeRun(
|
||||||
catalogEntityUid,
|
catalogEntityUid,
|
||||||
() => {
|
() => {
|
||||||
onRunDisposer?.();
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(onRun).not.toHaveBeenCalled();
|
expect(onRun).not.toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
@ -244,14 +233,11 @@ describe("<Catalog />", () => {
|
|||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
.spyOn(catalogEntityStore, "selectedItem", "get")
|
.spyOn(catalogEntityStore, "selectedItem", "get")
|
||||||
.mockImplementation(() => {
|
.mockImplementation(() => catalogEntityItem);
|
||||||
return catalogEntityItem;
|
|
||||||
});
|
|
||||||
|
|
||||||
const onRunDisposer = catalogEntityRegistry.addOnBeforeRun(
|
catalogEntityRegistry.addOnBeforeRun(
|
||||||
catalogEntityUid,
|
catalogEntityUid,
|
||||||
() => {
|
() => {
|
||||||
onRunDisposer?.();
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(onRun).not.toHaveBeenCalled();
|
expect(onRun).not.toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
@ -293,15 +279,11 @@ describe("<Catalog />", () => {
|
|||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
.spyOn(catalogEntityStore, "selectedItem", "get")
|
.spyOn(catalogEntityStore, "selectedItem", "get")
|
||||||
.mockImplementation(() => {
|
.mockImplementation(() => catalogEntityItem);
|
||||||
return catalogEntityItem;
|
|
||||||
});
|
|
||||||
|
|
||||||
const onRunDisposer = catalogEntityRegistry.addOnBeforeRun(
|
catalogEntityRegistry.addOnBeforeRun(
|
||||||
catalogEntityUid,
|
catalogEntityUid,
|
||||||
async () => {
|
async () => {
|
||||||
onRunDisposer?.();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -336,14 +318,11 @@ describe("<Catalog />", () => {
|
|||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
.spyOn(catalogEntityStore, "selectedItem", "get")
|
.spyOn(catalogEntityStore, "selectedItem", "get")
|
||||||
.mockImplementation(() => {
|
.mockImplementation(() => catalogEntityItem);
|
||||||
return catalogEntityItem;
|
|
||||||
});
|
|
||||||
|
|
||||||
const onRunDisposer = catalogEntityRegistry.addOnBeforeRun(
|
catalogEntityRegistry.addOnBeforeRun(
|
||||||
catalogEntityUid,
|
catalogEntityUid,
|
||||||
async () => {
|
async () => {
|
||||||
onRunDisposer?.();
|
|
||||||
expect(onRunTriggered).toBeFalsy();
|
expect(onRunTriggered).toBeFalsy();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -382,14 +361,11 @@ describe("<Catalog />", () => {
|
|||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
jest
|
jest
|
||||||
.spyOn(catalogEntityStore, "selectedItem", "get")
|
.spyOn(catalogEntityStore, "selectedItem", "get")
|
||||||
.mockImplementation(() => {
|
.mockImplementation(() => catalogEntityItem);
|
||||||
return catalogEntityItem;
|
|
||||||
});
|
|
||||||
|
|
||||||
const onRunDisposer = catalogEntityRegistry.addOnBeforeRun(
|
catalogEntityRegistry.addOnBeforeRun(
|
||||||
catalogEntityUid,
|
catalogEntityUid,
|
||||||
async () => {
|
async () => {
|
||||||
onRunDisposer?.();
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(onRun).not.toHaveBeenCalled();
|
expect(onRun).not.toHaveBeenCalled();
|
||||||
done();
|
done();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user