Skip to content

Commit

Permalink
add workflowEditorToolbarStore test
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectronicBlueberry committed Sep 25, 2023
1 parent 138d2bd commit a5f2f2b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions client/src/stores/workflowEditorToolbarStore.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
2 changes: 1 addition & 1 deletion client/src/stores/workflowEditorToolbarStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface InputCatcherEventListener {
callback: (event: InputCatcherEvent) => void;
}

interface InputCatcherEvent {
export interface InputCatcherEvent {
type: InputCatcherEventType;
position: [number, number];
}
Expand Down

0 comments on commit a5f2f2b

Please sign in to comment.