import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { MockTouchInputEntity } from "../../TouchController/Mock/MockTouchInput";
import { mockTouchInputEvent } from "../../TouchController/Mock/mockTouchInputEvent";
import { PinchSceneRootUC } from "../UC/PinchSceneRoot";
import { TouchPinch } from "./TouchPinch";
class MockPinch extends PinchSceneRootUC {
    constructor() {
        super(...arguments);
        this.sensitivity = 1;
        this.doPinch = jest.fn();
        this.initializePinch = jest.fn();
        this.finishPinch = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("app");
    new MockTouchInputEntity(app);
    const appObj = appObjects.getOrCreate("AO");
    const mockPinch = new MockPinch(appObj, PinchSceneRootUC.type);
    const pinchController = new 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 = mockTouchInputEvent([new Vector2(0, 0), new Vector2(79, 0)]);
        pinchController.onTouchStart(input);
        expect(mockPinch.initializePinch).toHaveBeenCalledWith(new Vector2(0, 0), new Vector2(79, 0));
    });
    it("Does not initialize if allow return false", () => {
        const { pinchController, mockPinch } = makeTestRig();
        pinchController.allow = () => {
            return false;
        };
        const input = mockTouchInputEvent([new Vector2(0, 0), new 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 = mockTouchInputEvent([
            new Vector2(0, 0),
            new Vector2(100, 0),
        ]);
        pinchController.onTouchStart(startInput);
        const moveInput = mockTouchInputEvent([
            new Vector2(-50, 0),
            new Vector2(100, 0),
        ]);
        pinchController.onTouchMove(moveInput);
        expect(mockPinch.doPinch).toHaveBeenCalledWith(new Vector2(-50, 0), new Vector2(100, 0));
    });
    it("Does not send on pinch if not initialized", () => {
        const { pinchController, mockPinch } = makeTestRig();
        const moveInput = mockTouchInputEvent([
            new Vector2(-50, 0),
            new Vector2(100, 0),
        ]);
        pinchController.onTouchMove(moveInput);
        expect(mockPinch.doPinch).not.toHaveBeenCalled();
    });
    it("Finishes the pinch", () => {
        const { pinchController, mockPinch } = makeTestRig();
        const startInput = mockTouchInputEvent([
            new Vector2(0, 0),
            new 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 = mockTouchInputEvent([new Vector2(0, 0), new 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 = mockTouchInputEvent([new Vector2(0, 0), new Vector2(79, 0)]);
        expect(pinchController.allow(evt)).toEqual(false);
    });
});
//# sourceMappingURL=TouchPinch.test.js.map