"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockTouchInput_1 = require("../../../TouchController/Mock/MockTouchInput");
const mockTouchInputEvent_1 = require("../../../TouchController/Mock/mockTouchInputEvent");
const MockPinchTransformUC_1 = require("../../Mocks/MockPinchTransformUC");
const PinchTransformTC_1 = require("./PinchTransformTC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const app = appObjects.getOrCreate("app");
    new MockTouchInput_1.MockTouchInputEntity(app);
    const appObj = appObjects.getOrCreate("AO");
    const mockPinch = new MockPinchTransformUC_1.MockPinchTransformUC(appObj);
    const pinchController = new PinchTransformTC_1.PinchTransformTC(appObj);
    return { pinchController, mockPinch };
}
describe("Touch Pinch Controller", () => {
    it("Initializes if allow return true", () => {
        const { pinchController, mockPinch } = makeTestRig();
        pinchController.allow = () => {
            return true;
        };
        const input = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(0, 0), new core_1.Vector2(79, 0)]);
        pinchController.onTouchStart(input);
        expect(mockPinch.initializePinch).toHaveBeenCalledWith(new core_1.Vector2(0, 0), new core_1.Vector2(79, 0));
    });
    it("Does not initialize if allow return false", () => {
        const { pinchController, mockPinch } = makeTestRig();
        pinchController.allow = () => {
            return false;
        };
        const input = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(0, 0), new core_1.Vector2(79, 0)]);
        pinchController.onTouchStart(input);
        expect(mockPinch.initializePinch).not.toHaveBeenCalled();
    });
    it("Sends updates the pinch if the fingers move after initialization", () => {
        const { pinchController, mockPinch } = makeTestRig();
        const startInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([
            new core_1.Vector2(0, 0),
            new core_1.Vector2(100, 0),
        ]);
        pinchController.onTouchStart(startInput);
        const moveInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([
            new core_1.Vector2(-50, 0),
            new core_1.Vector2(100, 0),
        ]);
        pinchController.onTouchMove(moveInput);
        expect(mockPinch.doPinch).toHaveBeenCalledWith(new core_1.Vector2(-50, 0), new core_1.Vector2(100, 0));
    });
    it("Does not send on pinch if not initialized", () => {
        const { pinchController, mockPinch } = makeTestRig();
        const moveInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([
            new core_1.Vector2(-50, 0),
            new core_1.Vector2(100, 0),
        ]);
        pinchController.onTouchMove(moveInput);
        expect(mockPinch.doPinch).not.toHaveBeenCalled();
    });
    it("Finishes the pinch", () => {
        const { pinchController, mockPinch } = makeTestRig();
        const startInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([
            new core_1.Vector2(0, 0),
            new core_1.Vector2(100, 0),
        ]);
        pinchController.onTouchStart(startInput);
        pinchController.onTouchEnd();
        expect(mockPinch.finishPinch).toHaveBeenCalled();
    });
});
//# sourceMappingURL=PinchTransformTC.test.js.map