"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 MockOrbitSceneRootUC_1 = require("../Mocks/MockOrbitSceneRootUC");
const MouseOrbit_1 = require("./MouseOrbit");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appAO = appObjects.getOrCreate("AO");
    const mockOrbit = new MockOrbitSceneRootUC_1.MockOrbitSceneRootUC(appAO);
    const mockMouseInput = new MockMouseInput_1.MockMouseInput(appAO);
    const orbitController = new MouseOrbit_1.MouseOrbit(appAO);
    const toolRepo = (0, Tools_1.makeToolRepo)(appObjects.getOrCreate("ToolRepo"));
    const orbitTool = toolRepo.makeTool("ORBIT");
    orbitTool.state = Tools_1.ToolState.ACTIVE;
    return { mockMouseInput, orbitController, mockOrbit, orbitTool };
}
describe("Mouse Orbit Controller", () => {
    it("Initializes Orbit", () => {
        const { orbitController, mockOrbit } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        orbitController.onDown(evt);
        expect(mockOrbit.initializeOrbit).toHaveBeenCalledWith(new core_2.Vector2(2, 3));
    });
    it("Does not initializes Orbit if not allowed", () => {
        const { orbitController, mockOrbit } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        orbitController.allow = () => {
            return false;
        };
        orbitController.onDown(evt);
        expect(mockOrbit.initializeOrbit).not.toHaveBeenCalled();
    });
    it("Sends a Orbit if it was initialized", () => {
        const { orbitController, mockOrbit } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        orbitController.onDown(evt);
        evt.position = new core_2.Vector2(4, 5);
        orbitController.onMove(evt);
        expect(mockOrbit.doOrbit).toHaveBeenCalledWith(new core_2.Vector2(4, 5));
    });
    it("Does not send a Orbit if it was notinitialized", () => {
        const { orbitController, mockOrbit } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        orbitController.onMove(evt);
        expect(mockOrbit.doOrbit).not.toHaveBeenCalled();
    });
    it("Finishes the orbit on up", () => {
        const { orbitController, mockOrbit } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        orbitController.onDown(evt);
        orbitController.onUp();
        expect(mockOrbit.finishOrbit).toHaveBeenCalled();
    });
    it("Allows orbit if the button is 2", () => {
        const { orbitController } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        expect(orbitController.allow(evt)).toEqual(true);
    });
    it("Allows Pan if the button is 0 and the tools is Orbit", () => {
        const { orbitController, orbitTool } = makeTestRig();
        orbitTool.state = Tools_1.ToolState.ACTIVE;
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        expect(orbitController.allow(evt)).toEqual(true);
    });
    it("Does not allow if the button is 0 but tool is not active", () => {
        const { orbitController, orbitTool } = makeTestRig();
        orbitTool.state = Tools_1.ToolState.ENABLED;
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        expect(orbitController.allow(evt)).toEqual(false);
    });
    it("Does not allow if the button is 1", () => {
        const { orbitController } = makeTestRig();
        const evt = {
            position: new core_2.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        expect(orbitController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=MouseOrbit.test.js.map