"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Tools_1 = require("../../Tools");
const MockTouchInput_1 = require("../../TouchController/Mock/MockTouchInput");
const mockTouchInputEvent_1 = require("../../TouchController/Mock/mockTouchInputEvent");
const Mocks_1 = require("../Mocks");
const TouchScale_1 = require("./TouchScale");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const app = appObjects.getOrCreate("app");
    new MockTouchInput_1.MockTouchInputEntity(app);
    const appObj = appObjects.getOrCreate("AO");
    const mockZoom = new Mocks_1.MockDragScaleSceneRootUC(appObj);
    const zoomController = new TouchScale_1.TouchScale(appObj);
    const toolRepo = (0, Tools_1.makeToolRepo)(appObjects.getOrCreate("ToolRepo"));
    const zoomTool = toolRepo.makeTool("ZOOM");
    zoomTool.state = Tools_1.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 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.Vector2(79, 0)]);
        zoomController.onTouchStart(input);
        expect(mockZoom.initializeScale).toHaveBeenCalledWith(new core_2.Vector2(79, 0));
    });
    it("Does not initialize if allow return false", () => {
        const { zoomController, mockZoom } = makeTestRig();
        zoomController.allow = () => {
            return false;
        };
        const input = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.Vector2(0, 0), new core_2.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 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.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 = Tools_1.ToolState.ACTIVE;
        const evt = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.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 = Tools_1.ToolState.ENABLED;
        const evt = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.Vector2(0, 0)]);
        expect(zoomController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=TouchScale.test.js.map