import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { MockMouseInput } from "../../MouseInput/Mocks/MockMouseInput";
import { makeToolRepo, ToolState } from "../../Tools";
import { MockPanSceneRootUC } from "../Mocks/MockPanSceneRootUC";
import { MousePan } from "./MousePan";
export function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appAO = appObjects.getOrCreate("AO");
    const mockPan = new MockPanSceneRootUC(appAO);
    const mockMouseInput = new MockMouseInput(appAO);
    const panController = new MousePan(appAO);
    const toolRepo = makeToolRepo(appObjects.getOrCreate("ToolRepo"));
    const panTool = toolRepo.makeTool("PAN");
    panTool.state = ToolState.ACTIVE;
    return { mockMouseInput, panController, mockPan, panTool };
}
describe("Mouse Pan Controller", () => {
    it("Initializes Pan", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onDown(evt);
        expect(mockPan.initializePan).toHaveBeenCalledWith(new Vector2(2, 3));
    });
    it("Sends a Pan if it was initialized", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onDown(evt);
        evt.position = new Vector2(4, 5);
        panController.onMove(evt);
        expect(mockPan.doPan).toHaveBeenCalledWith(new Vector2(4, 5));
    });
    it("Does not send a Pan if it was not initialized", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onMove(evt);
        expect(mockPan.doPan).not.toHaveBeenCalled();
    });
    it("Finishes the pan", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onDown(evt);
        panController.onUp();
        expect(mockPan.finishPan).toHaveBeenCalled();
    });
    it("Allows pan if the button is 1", () => {
        const { panController } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        expect(panController.allow(evt)).toEqual(true);
    });
    it("Allows Pan if the button is 0 and the tools is Pan", () => {
        const { panController, panTool } = makeTestRig();
        panTool.state = ToolState.ACTIVE;
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        expect(panController.allow(evt)).toEqual(true);
    });
    it("Does not allow if the button is 0 but Pan is not active", () => {
        const { panController, panTool } = makeTestRig();
        panTool.state = ToolState.ENABLED;
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        expect(panController.allow(evt)).toEqual(false);
    });
    it("Does not allow if the button is 2", () => {
        const { panController } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        expect(panController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=MousePan.test.js.map