import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { makeToolRepo, ToolState } from "../../Tools";
import { MockTouchInputEntity } from "../../TouchController/Mock/MockTouchInput";
import { mockTouchInputEvent } from "../../TouchController/Mock/mockTouchInputEvent";
import { MockDragScaleSceneRootUC } from "../Mocks";
import { TouchScale } from "./TouchScale";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("app");
    new MockTouchInputEntity(app);
    const appObj = appObjects.getOrCreate("AO");
    const mockZoom = new MockDragScaleSceneRootUC(appObj);
    const zoomController = new TouchScale(appObj);
    const toolRepo = makeToolRepo(appObjects.getOrCreate("ToolRepo"));
    const zoomTool = toolRepo.makeTool("ZOOM");
    zoomTool.state = ToolState.ACTIVE;
    return { zoomController, mockZoom, zoomTool };
}
describe("Touch Zoom Controller", () => {
    it("Initializes if allow return true", () => {
        const { zoomController, mockZoom } = makeTestRig();
        zoomController.allow = () => {
            return true;
        };
        const input = mockTouchInputEvent([new Vector2(79, 0)]);
        zoomController.onTouchStart(input);
        expect(mockZoom.initializeScale).toHaveBeenCalledWith(new Vector2(79, 0));
    });
    it("Does not initialize if allow return false", () => {
        const { zoomController, mockZoom } = makeTestRig();
        zoomController.allow = () => {
            return false;
        };
        const input = mockTouchInputEvent([new Vector2(0, 0), new Vector2(79, 0)]);
        zoomController.onTouchStart(input);
        expect(mockZoom.initializeScale).not.toHaveBeenCalled();
    });
    it("Does not send zoom if not initialized", () => {
        const { zoomController, mockZoom } = makeTestRig();
        const moveInput = mockTouchInputEvent([new Vector2(-50, 0)]);
        zoomController.onTouchMove(moveInput);
        expect(mockZoom.doScale).not.toHaveBeenCalled();
    });
    it("Finializes at the end", () => {
        const { zoomController, mockZoom } = makeTestRig();
        zoomController.onTouchEnd();
        expect(mockZoom.finishScaling).toHaveBeenCalled();
    });
    it("Allows Pan if the touch count is 1 and the tools is ZOOM", () => {
        const { zoomController, zoomTool } = makeTestRig();
        zoomTool.state = ToolState.ACTIVE;
        const evt = mockTouchInputEvent([new Vector2(0, 0)]);
        expect(zoomController.allow(evt)).toEqual(true);
    });
    it("Does not allow if the touch count is 1 but Zoom is not active", () => {
        const { zoomController, zoomTool } = makeTestRig();
        zoomTool.state = ToolState.ENABLED;
        const evt = mockTouchInputEvent([new Vector2(0, 0)]);
        expect(zoomController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=TouchScale.test.js.map