mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Test if onRun get trigger, and use inlineSnapshot
Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
parent
a9e6d8b7a0
commit
a877e109ba
@ -26,7 +26,7 @@ import { Catalog } from "./catalog";
|
|||||||
import { createMemoryHistory } from "history";
|
import { createMemoryHistory } from "history";
|
||||||
import { mockWindow } from "../../../../__mocks__/windowMock";
|
import { mockWindow } from "../../../../__mocks__/windowMock";
|
||||||
import { kubernetesClusterCategory } from "../../../common/catalog-entities/kubernetes-cluster";
|
import { kubernetesClusterCategory } from "../../../common/catalog-entities/kubernetes-cluster";
|
||||||
import { catalogCategoryRegistry, CatalogEntity } from "../../../common/catalog";
|
import { catalogCategoryRegistry } from "../../../common/catalog";
|
||||||
import { catalogEntityRegistry } from "../../../renderer/api/catalog-entity-registry";
|
import { catalogEntityRegistry } from "../../../renderer/api/catalog-entity-registry";
|
||||||
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
||||||
import { CatalogEntityItem } from "./catalog-entity-item";
|
import { CatalogEntityItem } from "./catalog-entity-item";
|
||||||
@ -34,8 +34,6 @@ import { CatalogEntityStore } from "./catalog-entity.store";
|
|||||||
|
|
||||||
mockWindow();
|
mockWindow();
|
||||||
|
|
||||||
const isCatalogEntityItem = (entity: any): entity is CatalogEntityItem<CatalogEntity> => typeof entity.enable === "boolean";
|
|
||||||
|
|
||||||
// avoid TypeError: Cannot read property 'getPath' of undefined
|
// avoid TypeError: Cannot read property 'getPath' of undefined
|
||||||
jest.mock("@electron/remote", () => {
|
jest.mock("@electron/remote", () => {
|
||||||
return {
|
return {
|
||||||
@ -115,9 +113,11 @@ describe("<Catalog />", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("can use catalogEntityRegistry.addOnRunHook to add hooks for catalog entities", (done) => {
|
it("can use catalogEntityRegistry.addOnRunHook to add hooks for catalog entities", (done) => {
|
||||||
|
const onRun = jest.fn();
|
||||||
const catalogEntityItem = new CatalogEntityItem({
|
const catalogEntityItem = new CatalogEntityItem({
|
||||||
...catalogEntity,
|
...catalogEntity,
|
||||||
...catalogEntityItemMethods,
|
...catalogEntityItemMethods,
|
||||||
|
onRun,
|
||||||
});
|
});
|
||||||
|
|
||||||
// mock as if there is a selected item > the detail panel opens
|
// mock as if there is a selected item > the detail panel opens
|
||||||
@ -129,27 +129,45 @@ describe("<Catalog />", () => {
|
|||||||
|
|
||||||
let hookGetCalled = false;
|
let hookGetCalled = false;
|
||||||
|
|
||||||
catalogEntityRegistry.addOnRunHook(catalogEntityUid, (entity) => {
|
const onRunDisposer = catalogEntityRegistry.addOnRunHook(
|
||||||
hookGetCalled = true;
|
catalogEntityUid,
|
||||||
expect(hookGetCalled).toBe(true);
|
(entity) => {
|
||||||
|
hookGetCalled = true;
|
||||||
|
expect(hookGetCalled).toBe(true);
|
||||||
|
|
||||||
expect(entity.apiVersion).toBe(catalogEntity.apiVersion);
|
onRunDisposer?.();
|
||||||
expect(entity.kind).toBe(catalogEntity.kind);
|
expect(entity).toMatchInlineSnapshot(`
|
||||||
|
Object {
|
||||||
if (isCatalogEntityItem(entity)) {
|
"apiVersion": "api",
|
||||||
expect(entity.enabled).toBe(catalogEntity.enabled);
|
"enabled": true,
|
||||||
|
"getId": [Function],
|
||||||
|
"getName": [Function],
|
||||||
|
"kind": "kind",
|
||||||
|
"metadata": Object {
|
||||||
|
"labels": Object {
|
||||||
|
"test": "label",
|
||||||
|
},
|
||||||
|
"name": "a catalog entity",
|
||||||
|
"uid": "a_catalogEntity_uid",
|
||||||
|
},
|
||||||
|
"onContextMenuOpen": [Function],
|
||||||
|
"onRun": [MockFunction],
|
||||||
|
"onSettingsOpen": [Function],
|
||||||
|
"spec": Object {},
|
||||||
|
"status": Object {
|
||||||
|
"phase": "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(onRun).toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
}, 800);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
);
|
||||||
if (!isCatalogEntityItem(entity)) {
|
|
||||||
expect(entity.metadata).toBe(catalogEntity.metadata);
|
|
||||||
expect(entity.status).toBe(catalogEntity.status);
|
|
||||||
expect(entity.spec).toBe(catalogEntity.spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<Catalog history={history} location={mockLocation} match={mockMatch} />
|
<Catalog history={history} location={mockLocation} match={mockMatch} />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user