import { makeAppObjectRepo, Vector2 } from "@vived/core";
import { MockTouchInputEntity } from "../../../TouchController/Mock/MockTouchInput";
import { mockTouchInputEvent } from "../../../TouchController/Mock/mockTouchInputEvent";
import { MockPinchTransformUC } from "../../Mocks/MockPinchTransformUC";
import { PinchTransformTC } from "./PinchTransformTC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("app");
    new MockTouchInputEntity(app);
    const appObj = appObjects.getOrCreate("AO");
    const mockPinch = new MockPinchTransformUC(appObj);
    const pinchController = new 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 = 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();
    });
});
//# sourceMappingURL=PinchTransformTC.test.js.map