"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const MockTouchInput_1 = require("../../TouchController/Mock/MockTouchInput");
const mockTouchInputEvent_1 = require("../../TouchController/Mock/mockTouchInputEvent");
const PinchSceneRoot_1 = require("../UC/PinchSceneRoot");
const TouchPinch_1 = require("./TouchPinch");
class MockPinch extends PinchSceneRoot_1.PinchSceneRootUC {
    constructor() {
        super(...arguments);
        this.sensitivity = 1;
        this.doPinch = jest.fn();
        this.initializePinch = jest.fn();
        this.finishPinch = jest.fn();
    }
}
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 MockPinch(appObj, PinchSceneRoot_1.PinchSceneRootUC.type);
    const pinchController = new TouchPinch_1.TouchPinch(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_2.Vector2(0, 0), new core_2.Vector2(79, 0)]);
        pinchController.onTouchStart(input);
        expect(mockPinch.initializePinch).toHaveBeenCalledWith(new core_2.Vector2(0, 0), new core_2.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_2.Vector2(0, 0), new core_2.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_2.Vector2(0, 0),
            new core_2.Vector2(100, 0),
        ]);
        pinchController.onTouchStart(startInput);
        const moveInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([
            new core_2.Vector2(-50, 0),
            new core_2.Vector2(100, 0),
        ]);
        pinchController.onTouchMove(moveInput);
        expect(mockPinch.doPinch).toHaveBeenCalledWith(new core_2.Vector2(-50, 0), new core_2.Vector2(100, 0));
    });
    it("Does not send on pinch if not initialized", () => {
        const { pinchController, mockPinch } = makeTestRig();
        const moveInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([
            new core_2.Vector2(-50, 0),
            new core_2.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_2.Vector2(0, 0),
            new core_2.Vector2(100, 0),
        ]);
        pinchController.onTouchStart(startInput);
        pinchController.onTouchEnd();
        expect(mockPinch.finishPinch).toHaveBeenCalled();
    });
    it("Allows pan if the touch count is 2 and the touches are greater than 80px apart", () => {
        const { pinchController } = makeTestRig();
        const evt = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.Vector2(0, 0), new core_2.Vector2(81, 0)]);
        expect(pinchController.allow(evt)).toEqual(true);
    });
    it("Does not allow pan if the touch count is 2 and the touches are less than 80px apart", () => {
        const { pinchController } = makeTestRig();
        const evt = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.Vector2(0, 0), new core_2.Vector2(79, 0)]);
        expect(pinchController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=TouchPinch.test.js.map