import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { MockMouseInput } from "../../MouseInput/Mocks/MockMouseInput";
import { makeToolRepo, ToolState } from "../../Tools";
import { MockDragScaleSceneRootUC } from "../Mocks/MockDragScaleSceneRootUC";
import { MouseScale } from "./MouseScale";
export function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appAO = appObjects.getOrCreate("AO");
    const mockDrag = new MockDragScaleSceneRootUC(appAO);
    const mockMouseInput = new MockMouseInput(appAO);
    const scaleRootController = new MouseScale(appAO);
    const toolRepo = makeToolRepo(appObjects.getOrCreate("ToolRepo"));
    const zoomTool = toolRepo.makeTool("ZOOM");
    zoomTool.state = ToolState.ACTIVE;
    return {
        appObjects,
        scaleRootController,
        mockDrag,
        mockMouseInput,
        zoomTool,
    };
}
describe("Mouse Dolly Controller", () => {
    it("Initializes dolly", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        scaleRootController.onDown(evt);
        expect(mockDrag.initializeScale).toHaveBeenCalledWith(new Vector2(2, 3));
    });
    it("Sends a dolly if it was initialized", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        scaleRootController.onDown(evt);
        evt.position = new Vector2(4, 5);
        scaleRootController.onMove(evt);
        expect(mockDrag.doScale).toHaveBeenCalledWith(new Vector2(4, 5));
    });
    it("Does not send a dolly if it was notinitialized", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        scaleRootController.onMove(evt);
        expect(mockDrag.doScale).not.toHaveBeenCalled();
    });
    it("Finializes at the end", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        scaleRootController.onUp();
        expect(mockDrag.finishScaling).toHaveBeenCalled();
    });
    it("Does not allow if the button is 1", () => {
        const { scaleRootController } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        expect(scaleRootController.allow(evt)).toEqual(false);
    });
    it("Allows if the button is 0 and the tools is Zoom", () => {
        const { scaleRootController, zoomTool } = makeTestRig();
        zoomTool.state = ToolState.ACTIVE;
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        expect(scaleRootController.allow(evt)).toEqual(true);
    });
    it("Does not allow if the button is 0 but Zoom is not active", () => {
        const { scaleRootController, zoomTool } = makeTestRig();
        zoomTool.state = ToolState.DISABLED;
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        expect(scaleRootController.allow(evt)).toEqual(false);
    });
    it("Does not allow if the button is 2", () => {
        const { scaleRootController } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        expect(scaleRootController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=MouseScale.test.js.map