"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const TouchInput_1 = require("../../TouchController/Entities/TouchInput");
const mockTouchInputEvent_1 = require("../../TouchController/Mock/mockTouchInputEvent");
const TryAddCalloutMock_1 = require("../Mocks/TryAddCalloutMock");
const TouchAddCalloutTC_1 = require("./TouchAddCalloutTC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const touchInput = (0, TouchInput_1.makeTouchInput)(appObjects.getOrCreate("Input"));
    const registerSpy = jest.spyOn(touchInput, "registerController");
    const addMock = (0, TryAddCalloutMock_1.makeTryAddCalloutMock)(appObjects);
    addMock.initializeWithPixel.mockReturnValue(true);
    const controller = new TouchAddCalloutTC_1.TouchAddCalloutTC(appObjects.getOrCreate("AO"));
    return {
        registerSpy,
        controller,
        addMock,
    };
}
describe("Test Touch Callout Controller", () => {
    it("Registers with the mouse input when constructed", () => {
        const { registerSpy, controller } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(controller);
    });
    it("Initializes the UC when a single touch", () => {
        const { controller, addMock } = makeTestRig();
        const evt = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(2, 3)]);
        controller.onTouchStart(evt);
        expect(addMock.initializeWithPixel).toHaveBeenCalledWith(new core_1.Vector2(2, 3));
    });
    it("Does not initialize if the touch count is more than one", () => {
        const { controller, addMock } = makeTestRig();
        const evt = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(2, 3), core_1.Vector2.Zero()]);
        controller.onTouchStart(evt);
        expect(addMock.initializeWithPixel).not.toHaveBeenCalled();
    });
    it("Moving updates after a successful down", () => {
        const { controller, addMock } = makeTestRig();
        const evt1 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(2, 3)]);
        controller.onTouchStart(evt1);
        const evt2 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(4, 5)]);
        controller.onTouchMove(evt2);
        expect(addMock.moveWithPixel).toHaveBeenCalledWith(new core_1.Vector2(4, 5));
    });
    it("Cancels if more fingers are touched", () => {
        const { controller, addMock } = makeTestRig();
        const evt1 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(2, 3)]);
        controller.onTouchStart(evt1);
        const evt2 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(2, 3), new core_1.Vector2(4, 5)]);
        controller.onTouchStart(evt2);
        expect(addMock.cancel).toHaveBeenCalled();
    });
    it("Moving does not updates without a down", () => {
        const { controller, addMock } = makeTestRig();
        const evt2 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(4, 5)]);
        controller.onTouchMove(evt2);
        expect(addMock.moveWithPixel).not.toHaveBeenCalled();
    });
    it("Stop updates after a successful down", () => {
        const { controller, addMock } = makeTestRig();
        const evt1 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(2, 3)]);
        controller.onTouchStart(evt1);
        controller.onTouchEnd();
        expect(addMock.stop).toHaveBeenCalled();
    });
    it("Stop does not updates without a down", () => {
        const { controller, addMock } = makeTestRig();
        controller.onTouchEnd();
        expect(addMock.stop).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=TouchAddCalloutTC.test.js.map