"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const TouchController_1 = require("../../../TouchController");
const TryPanTransformUcMock_1 = require("../../Mocks/TryPanTransformUcMock");
const TouchPanTransformTC_1 = require("./TouchPanTransformTC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = appObjects.getOrCreate("appObj");
    const mockUC = new TryPanTransformUcMock_1.TryPanTransformUcMock(appObj);
    const input = (0, TouchController_1.makeTouchInput)(appObj);
    const registerSpy = jest.spyOn(input, "registerController");
    const controller = new TouchPanTransformTC_1.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 = (0, TouchController_1.mockTouchInputEvent)([new core_1.Vector2(1, 2)]);
        controller.onTouchStart(event);
        expect(mockUC.tryWithPixel).toHaveBeenCalledWith(new core_1.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 = (0, TouchController_1.mockTouchInputEvent)([new core_1.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 = (0, TouchController_1.mockTouchInputEvent)([new core_1.Vector2(1, 2), new core_1.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 = (0, TouchController_1.mockTouchInputEvent)([new core_1.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 = (0, TouchController_1.mockTouchInputEvent)([new core_1.Vector2(1, 2)]);
        controller.onTouchStart(event);
        const event2 = (0, TouchController_1.mockTouchInputEvent)([new core_1.Vector2(3, 4)]);
        controller.onTouchMove(event2);
        expect(mockUC.moveWithPixel).toHaveBeenCalledWith(new core_1.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 = (0, TouchController_1.mockTouchInputEvent)([new core_1.Vector2(1, 2)]);
        controller.onTouchStart(event);
        controller.onTouchEnd();
        expect(mockUC.stop).toHaveBeenCalled();
    });
});
//# sourceMappingURL=TouchPanTransformTC.test.js.map