import { makeAppObjectRepo, Vector2 } from "@vived/core";
import { makeTouchInput } from "../../TouchController/Entities/TouchInput";
import { mockTouchInputEvent } from "../../TouchController/Mock/mockTouchInputEvent";
import { makeTryAddCalloutMock } from "../Mocks/TryAddCalloutMock";
import { TouchAddCalloutTC } from "./TouchAddCalloutTC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const touchInput = makeTouchInput(appObjects.getOrCreate("Input"));
    const registerSpy = jest.spyOn(touchInput, "registerController");
    const addMock = makeTryAddCalloutMock(appObjects);
    addMock.initializeWithPixel.mockReturnValue(true);
    const controller = new 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 = mockTouchInputEvent([new Vector2(2, 3)]);
        controller.onTouchStart(evt);
        expect(addMock.initializeWithPixel).toHaveBeenCalledWith(new Vector2(2, 3));
    });
    it("Does not initialize if the touch count is more than one", () => {
        const { controller, addMock } = makeTestRig();
        const evt = mockTouchInputEvent([new Vector2(2, 3), Vector2.Zero()]);
        controller.onTouchStart(evt);
        expect(addMock.initializeWithPixel).not.toHaveBeenCalled();
    });
    it("Moving updates after a successful down", () => {
        const { controller, addMock } = makeTestRig();
        const evt1 = mockTouchInputEvent([new Vector2(2, 3)]);
        controller.onTouchStart(evt1);
        const evt2 = mockTouchInputEvent([new Vector2(4, 5)]);
        controller.onTouchMove(evt2);
        expect(addMock.moveWithPixel).toHaveBeenCalledWith(new Vector2(4, 5));
    });
    it("Cancels if more fingers are touched", () => {
        const { controller, addMock } = makeTestRig();
        const evt1 = mockTouchInputEvent([new Vector2(2, 3)]);
        controller.onTouchStart(evt1);
        const evt2 = mockTouchInputEvent([new Vector2(2, 3), new Vector2(4, 5)]);
        controller.onTouchStart(evt2);
        expect(addMock.cancel).toHaveBeenCalled();
    });
    it("Moving does not updates without a down", () => {
        const { controller, addMock } = makeTestRig();
        const evt2 = mockTouchInputEvent([new Vector2(4, 5)]);
        controller.onTouchMove(evt2);
        expect(addMock.moveWithPixel).not.toHaveBeenCalled();
    });
    it("Stop updates after a successful down", () => {
        const { controller, addMock } = makeTestRig();
        const evt1 = mockTouchInputEvent([new 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