import { makeAppObjectRepo, Vector2 } from "@vived/core";
import { makeTouchInput, mockTouchInputEvent } from "../../../TouchController";
import { TryPanTransformUcMock } from "../../Mocks/TryPanTransformUcMock";
import { TouchPanTransformTC } from "./TouchPanTransformTC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObj = appObjects.getOrCreate("appObj");
    const mockUC = new TryPanTransformUcMock(appObj);
    const input = makeTouchInput(appObj);
    const registerSpy = jest.spyOn(input, "registerController");
    const controller = new TouchPanTransformTC(appObj);
    return {
        controller,
        mockUC,
        appObjects,
        registerSpy,
    };
}
describe("Try Touch Pan Transform", () => {
    it("Registers as a controller", () => {
        const { registerSpy, controller } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(controller);
    });
    it("Calls initialize on the use case if all is good", () => {
        const { mockUC, controller } = makeTestRig();
        const event = mockTouchInputEvent([new Vector2(1, 2)]);
        controller.onTouchStart(event);
        expect(mockUC.tryWithPixel).toHaveBeenCalledWith(new Vector2(1, 2));
    });
    it("Does not calls initialize on the use case if allow returns false", () => {
        const { mockUC, controller } = makeTestRig();
        controller.allow = () => {
            return false;
        };
        const event = mockTouchInputEvent([new Vector2(1, 2)]);
        controller.onTouchStart(event);
        expect(mockUC.tryWithPixel).not.toHaveBeenCalled();
    });
    it("Does not calls initialize on the use case if multiple touches are detected", () => {
        const { mockUC, controller } = makeTestRig();
        const event = mockTouchInputEvent([new Vector2(1, 2), new Vector2(3, 4)]);
        controller.onTouchStart(event);
        expect(mockUC.tryWithPixel).not.toHaveBeenCalled();
    });
    it("Does not calls move on the use case if touch start was not called first", () => {
        const { mockUC, controller } = makeTestRig();
        const event = mockTouchInputEvent([new Vector2(1, 2)]);
        controller.onTouchMove(event);
        expect(mockUC.moveWithPixel).not.toHaveBeenCalled();
    });
    it("Calls move on the use case if touch start was called first", () => {
        const { mockUC, controller } = makeTestRig();
        mockUC.tryWithPixel.mockReturnValueOnce(true);
        const event = mockTouchInputEvent([new Vector2(1, 2)]);
        controller.onTouchStart(event);
        const event2 = mockTouchInputEvent([new Vector2(3, 4)]);
        controller.onTouchMove(event2);
        expect(mockUC.moveWithPixel).toHaveBeenCalledWith(new Vector2(3, 4));
    });
    it("Does not calls stop on the use case if touch start was not called first", () => {
        const { mockUC, controller } = makeTestRig();
        controller.onTouchEnd();
        expect(mockUC.stop).not.toHaveBeenCalled();
    });
    it("Calls stop on the use case if touch start was called first", () => {
        const { mockUC, controller } = makeTestRig();
        mockUC.tryWithPixel.mockReturnValueOnce(true);
        const event = mockTouchInputEvent([new Vector2(1, 2)]);
        controller.onTouchStart(event);
        controller.onTouchEnd();
        expect(mockUC.stop).toHaveBeenCalled();
    });
});
//# sourceMappingURL=TouchPanTransformTC.test.js.map