"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeTestRig = makeTestRig;
const core_1 = require("@vived/core");
const MockMouseInput_1 = require("../../../MouseInput/Mocks/MockMouseInput");
const Mocks_1 = require("../../Mocks");
const DragScaleTransformMC_1 = require("./DragScaleTransformMC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appAO = appObjects.getOrCreate("AO");
    const mockDrag = new Mocks_1.MockRayScaleTransform(appAO);
    const mockMouseInput = new MockMouseInput_1.MockMouseInput(appObjects.getOrCreate("MouseController"));
    const scaleRootController = new DragScaleTransformMC_1.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 core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        scaleRootController.allow = () => {
            return true;
        };
        scaleRootController.onDown(evt);
        expect(mockDrag.initializePixel).toHaveBeenCalledWith(new core_1.Vector2(2, 3));
    });
    it("Does not initializes dolly if allow returns false", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new core_1.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 core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        scaleRootController.onDown(evt);
        evt.position = new core_1.Vector2(4, 5);
        scaleRootController.onMove(evt);
        expect(mockDrag.updatePixel).toHaveBeenCalledWith(new core_1.Vector2(4, 5));
    });
    it("Does not send a dolly if it was notinitialized", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new core_1.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