Add addOnRunHook return false test

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen committed 2021-10-05 09:02:54 +03:00
1 parent fcdd0323e0
commit d65e9700f3
1 file changed
+45 -1
@@ -167,7 +167,7 @@ describe("<Catalog />", () => {
setTimeout(() => {
expect(onRun).toHaveBeenCalled();
done();
}, 800);
}, 500);
return true;
}
@@ -184,4 +184,48 @@ describe("<Catalog />", () => {
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"));
});
});