"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeTestRig = makeTestRig;
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const MockMouseInput_1 = require("../../MouseInput/Mocks/MockMouseInput");
const Tools_1 = require("../../Tools");
const MockDragScaleSceneRootUC_1 = require("../Mocks/MockDragScaleSceneRootUC");
const MouseScale_1 = require("./MouseScale");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appAO = appObjects.getOrCreate("AO");
    const mockDrag = new MockDragScaleSceneRootUC_1.MockDragScaleSceneRootUC(appAO);
    const mockMouseInput = new MockMouseInput_1.MockMouseInput(appAO);
    const scaleRootController = new MouseScale_1.MouseScale(appAO);
    const toolRepo = (0, Tools_1.makeToolRepo)(appObjects.getOrCreate("ToolRepo"));
    const zoomTool = toolRepo.makeTool("ZOOM");
    zoomTool.state = Tools_1.ToolState.ACTIVE;
    return {
        appObjects,
        scaleRootController,
        mockDrag,
        mockMouseInput,
        zoomTool,
    };
}
describe("Mouse Dolly Controller", () => {
    it("Initializes dolly", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        scaleRootController.onDown(evt);
        expect(mockDrag.initializeScale).toHaveBeenCalledWith(new core_2.Vector2(2, 3));
    });
    it("Sends a dolly if it was initialized", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        scaleRootController.onDown(evt);
        evt.position = new core_2.Vector2(4, 5);
        scaleRootController.onMove(evt);
        expect(mockDrag.doScale).toHaveBeenCalledWith(new core_2.Vector2(4, 5));
    });
    it("Does not send a dolly if it was notinitialized", () => {
        const { scaleRootController, mockDrag } = makeTestRig();
        const evt = {
            position: new core_2.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 core_2.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 = Tools_1.ToolState.ACTIVE;
        const evt = {
            position: new core_2.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 = Tools_1.ToolState.DISABLED;
        const evt = {
            position: new core_2.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 core_2.Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        expect(scaleRootController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=MouseScale.test.js.map