import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { MockMouseInput } from "../../MouseInput/Mocks/MockMouseInput";
import { makeToolRepo, ToolState } from "../../Tools";
import { MockOrbitSceneRootUC } from "../Mocks/MockOrbitSceneRootUC";
import { MouseOrbit } from "./MouseOrbit";
export function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appAO = appObjects.getOrCreate("AO");
    const mockOrbit = new MockOrbitSceneRootUC(appAO);
    const mockMouseInput = new MockMouseInput(appAO);
    const orbitController = new MouseOrbit(appAO);
    const toolRepo = makeToolRepo(appObjects.getOrCreate("ToolRepo"));
    const orbitTool = toolRepo.makeTool("ORBIT");
    orbitTool.state = ToolState.ACTIVE;
    return { mockMouseInput, orbitController, mockOrbit, orbitTool };
}
describe("Mouse Orbit Controller", () => {
    it("Initializes Orbit", () => {
        const { orbitController, mockOrbit } = makeTestRig();
        const evt = {
            position: new Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        orbitController.onDown(evt);
        expect(mockOrbit.initializeOrbit).toHaveBeenCalledWith(new Vector2(2, 3));
    });
    it("Does not initializes Orbit if not allowed", () => {
        const { orbitController, mockOrbit } = makeTestRig();
        const evt = {
            position: new 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 Vector2(2, 3),
            button: 2,
            event: new MouseEvent("buttondown"),
        };
        orbitController.onDown(evt);
        evt.position = new Vector2(4, 5);
        orbitController.onMove(evt);
        expect(mockOrbit.doOrbit).toHaveBeenCalledWith(new Vector2(4, 5));
    });
    it("Does not send a Orbit if it was notinitialized", () => {
        const { orbitController, mockOrbit } = makeTestRig();
        const evt = {
            position: new 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 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 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 = ToolState.ACTIVE;
        const evt = {
            position: new 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 = ToolState.ENABLED;
        const evt = {
            position: new 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 Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        expect(orbitController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=MouseOrbit.test.js.map