diff --git a/client/src/stores/workflowEditorToolbarStore.test.ts b/client/src/stores/workflowEditorToolbarStore.test.ts new file mode 100644 index 000000000000..f268c9c1cee2 --- /dev/null +++ b/client/src/stores/workflowEditorToolbarStore.test.ts @@ -0,0 +1,32 @@ +import { createPinia, setActivePinia } from "pinia"; + +import { type InputCatcherEvent, useWorkflowEditorToolbarStore } from "./workflowEditorToolbarStore"; + +describe("workflowEditorToolbarStore", () => { + beforeEach(() => { + setActivePinia(createPinia()); + }); + + it("has an input catcher event bus", () => { + const toolbarStore = useWorkflowEditorToolbarStore("mock-workflow-id"); + + const receivedEvents: InputCatcherEvent[] = []; + + toolbarStore.onInputCatcherEvent("pointerdown", (e) => receivedEvents.push(e)); + toolbarStore.onInputCatcherEvent("pointerup", (e) => receivedEvents.push(e)); + toolbarStore.onInputCatcherEvent("pointermove", (e) => receivedEvents.push(e)); + toolbarStore.onInputCatcherEvent("temporarilyDisabled", (e) => receivedEvents.push(e)); + + toolbarStore.emitInputCatcherEvent("pointerdown", { type: "pointerdown", position: [100, 200] }); + expect(receivedEvents.length).toBe(1); + expect(receivedEvents[0]?.position).toEqual([100, 200]); + + toolbarStore.emitInputCatcherEvent("pointermove", { type: "pointermove", position: [0, 0] }); + toolbarStore.emitInputCatcherEvent("pointerup", { type: "pointerup", position: [0, 0] }); + toolbarStore.emitInputCatcherEvent("temporarilyDisabled", { type: "temporarilyDisabled", position: [0, 0] }); + + expect(receivedEvents[1]?.type).toBe("pointermove"); + expect(receivedEvents[2]?.type).toBe("pointerup"); + expect(receivedEvents[3]?.type).toBe("temporarilyDisabled"); + }); +}); diff --git a/client/src/stores/workflowEditorToolbarStore.ts b/client/src/stores/workflowEditorToolbarStore.ts index 2b3f0b2264f2..32bac6774b67 100644 --- a/client/src/stores/workflowEditorToolbarStore.ts +++ b/client/src/stores/workflowEditorToolbarStore.ts @@ -15,7 +15,7 @@ interface InputCatcherEventListener { callback: (event: InputCatcherEvent) => void; } -interface InputCatcherEvent { +export interface InputCatcherEvent { type: InputCatcherEventType; position: [number, number]; }