Change onBeforeRun API (#3981)

Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Juho HeikkaandSebastian Malton authored and GitHub committed 2021-10-07 12:43:50 -04:00
1 parent 58f7bcb38d
commit 724b9450a6
4 files changed
+82 -59

No files matched your search

@@ -129,9 +129,8 @@ describe("<Catalog />", () => {
.mockImplementation(() => catalogEntityItem);
catalogEntityRegistry.addOnBeforeRun(
catalogEntityUid,
(entity) => {
expect(entity).toMatchInlineSnapshot(`
(event) => {
expect(event.target).toMatchInlineSnapshot(`
Object {
"apiVersion": "api",
"enabled": true,
@@ -159,8 +158,6 @@ describe("<Catalog />", () => {
expect(onRun).toHaveBeenCalled();
done();
}, 500);
return true;
}
);
@@ -176,7 +173,7 @@ describe("<Catalog />", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
it("onBeforeRun return false => onRun wont be triggered", (done) => {
it("onBeforeRun prevents event => onRun wont be triggered", (done) => {
const catalogCategoryRegistry = new CatalogCategoryRegistry();
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
@@ -193,14 +190,12 @@ describe("<Catalog />", () => {
.mockImplementation(() => catalogEntityItem);
catalogEntityRegistry.addOnBeforeRun(
catalogEntityUid,
() => {
(e) => {
setTimeout(() => {
expect(onRun).not.toHaveBeenCalled();
done();
}, 500);
return false;
e.preventDefault();
}
);
@@ -216,7 +211,7 @@ describe("<Catalog />", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
it("addOnBeforeRun throw an exception => onRun wont be triggered", (done) => {
it("addOnBeforeRun throw an exception => onRun will be triggered", (done) => {
const catalogCategoryRegistry = new CatalogCategoryRegistry();
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
@@ -233,10 +228,9 @@ describe("<Catalog />", () => {
.mockImplementation(() => catalogEntityItem);
catalogEntityRegistry.addOnBeforeRun(
catalogEntityUid,
() => {
setTimeout(() => {
expect(onRun).not.toHaveBeenCalled();
expect(onRun).toHaveBeenCalled();
done();
}, 500);
@@ -256,7 +250,7 @@ describe("<Catalog />", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
it("addOnRunHook return a promise and resolve true => onRun()", (done) => {
it("addOnRunHook return a promise and does not prevent run event => onRun()", (done) => {
const catalogCategoryRegistry = new CatalogCategoryRegistry();
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
@@ -273,9 +267,8 @@ describe("<Catalog />", () => {
.mockImplementation(() => catalogEntityItem);
catalogEntityRegistry.addOnBeforeRun(
catalogEntityUid,
async () => {
return true;
// no op
}
);
@@ -291,7 +284,7 @@ describe("<Catalog />", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
it("addOnRunHook return a promise and resolve false => onRun() wont be triggered", (done) => {
it("addOnRunHook return a promise and prevents event wont be triggered", (done) => {
const catalogCategoryRegistry = new CatalogCategoryRegistry();
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
@@ -308,8 +301,7 @@ describe("<Catalog />", () => {
.mockImplementation(() => catalogEntityItem);
catalogEntityRegistry.addOnBeforeRun(
catalogEntityUid,
async () => {
async (e) => {
expect(onRun).not.toBeCalled();
setTimeout(() => {
@@ -317,7 +309,7 @@ describe("<Catalog />", () => {
done();
}, 500);
return false;
e.preventDefault();
}
);
@@ -333,7 +325,7 @@ describe("<Catalog />", () => {
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
});
it("addOnRunHook return a promise and reject => onRun wont be triggered", (done) => {
it("addOnRunHook return a promise and reject => onRun will be triggered", (done) => {
const catalogCategoryRegistry = new CatalogCategoryRegistry();
const catalogEntityRegistry = new CatalogEntityRegistry(catalogCategoryRegistry);
const catalogEntityStore = new CatalogEntityStore(catalogEntityRegistry);
@@ -350,10 +342,9 @@ describe("<Catalog />", () => {
.mockImplementation(() => catalogEntityItem);
catalogEntityRegistry.addOnBeforeRun(
catalogEntityUid,
async () => {
setTimeout(() => {
expect(onRun).not.toHaveBeenCalled();
expect(onRun).toHaveBeenCalled();
done();
}, 500);