"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 MockPanSceneRootUC_1 = require("../Mocks/MockPanSceneRootUC");
const MousePan_1 = require("./MousePan");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appAO = appObjects.getOrCreate("AO");
    const mockPan = new MockPanSceneRootUC_1.MockPanSceneRootUC(appAO);
    const mockMouseInput = new MockMouseInput_1.MockMouseInput(appAO);
    const panController = new MousePan_1.MousePan(appAO);
    const toolRepo = (0, Tools_1.makeToolRepo)(appObjects.getOrCreate("ToolRepo"));
    const panTool = toolRepo.makeTool("PAN");
    panTool.state = Tools_1.ToolState.ACTIVE;
    return { mockMouseInput, panController, mockPan, panTool };
}
describe("Mouse Pan Controller", () => {
    it("Initializes Pan", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onDown(evt);
        expect(mockPan.initializePan).toHaveBeenCalledWith(new core_2.Vector2(2, 3));
    });
    it("Sends a Pan if it was initialized", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onDown(evt);
        evt.position = new core_2.Vector2(4, 5);
        panController.onMove(evt);
        expect(mockPan.doPan).toHaveBeenCalledWith(new core_2.Vector2(4, 5));
    });
    it("Does not send a Pan if it was not initialized", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new core_2.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 core_2.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 core_2.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 = Tools_1.ToolState.ACTIVE;
        const evt = {
            position: new core_2.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 = Tools_1.ToolState.ENABLED;
        const evt = {
            position: new core_2.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 core_2.Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        expect(panController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=MousePan.test.js.map