import { makeAppObjectRepo, Vector2 } from "@vived/core";
import { MockMouseInput } from "../../../MouseInput/Mocks/MockMouseInput";
import { MockRayScaleTransform } from "../../Mocks";
import { DragScaleTransformMC } from "./DragScaleTransformMC";
export function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appAO = appObjects.getOrCreate("AO");
    const mockDrag = new MockRayScaleTransform(appAO);
    const mockMouseInput = new MockMouseInput(appObjects.getOrCreate("MouseController"));
    const scaleRootController = new DragScaleTransformMC(appAO);
    return { appObjects, scaleRootController, mockDrag, mockMouseInput };
}
describe("Mouse Dolly Controller", () => {
    it("Initializes dolly if allow returns true", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        scaleRootController.allow = () => {
            return true;
        };
        scaleRootController.onDown(evt);
        expect(mockDrag.initializePixel).toHaveBeenCalledWith(new Vector2(2, 3));
    });
    it("Does not initializes dolly if allow returns false", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        scaleRootController.allow = () => {
            return false;
        };
        scaleRootController.onDown(evt);
        expect(mockDrag.initializePixel).not.toHaveBeenCalled();
    });
    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.updatePixel).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.updatePixel).not.toHaveBeenCalled();
    });
    it("Finializes at the end", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        scaleRootController.onUp();
        expect(mockDrag.finish).toHaveBeenCalled();
    });
});
//# sourceMappingURL=DragScaleTransformMC.test.js.map