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

Add addOnRunHook return false test

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen 2021-10-05 09:02:54 +03:00
parent fcdd0323e0
commit d65e9700f3
No known key found for this signature in database
GPG Key ID: 54B44603D251B788

View File

@ -167,7 +167,7 @@ describe("<Catalog />", () => {
setTimeout(() => { setTimeout(() => {
expect(onRun).toHaveBeenCalled(); expect(onRun).toHaveBeenCalled();
done(); done();
}, 800); }, 500);
return true; return true;
} }
@ -184,4 +184,48 @@ describe("<Catalog />", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon")); 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(
<Catalog
history={history}
location={mockLocation}
match={mockMatch}
catalogEntityStore={catalogEntityStore}
/>
);
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
}); });