import { makeAppObjectRepo } from "@vived/core";
import { Vector2 } from "@vived/core";
import { MockTouchInputEntity } from "../../TouchController/Mock/MockTouchInput";
import { mockTouchInputEvent } from "../../TouchController/Mock/mockTouchInputEvent";
import { MockFocusOnPixelUC } from "../Mocks/MockFocusOnPixelUC";
import { DoubleTapToFocus } from "./DoubleTapToFocus";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("app");
    new MockTouchInputEntity(app);
    const appAO = appObjects.getOrCreate("AO");
    const mockCenterUC = new MockFocusOnPixelUC(appAO);
    const tapController = new DoubleTapToFocus(appAO);
    return { tapController, mockCenterUC };
}
describe("Double Tap to focus Controller", () => {
    it("Calls the focus UC when a double tap occurs within the time limit", () => {
        const { tapController, mockCenterUC } = makeTestRig();
        const touch = mockTouchInputEvent([new Vector2(1, 2)]);
        const dateNowMock = jest.fn();
        Date.now = dateNowMock;
        dateNowMock.mockReturnValue(0);
        tapController.onTouchStart(touch);
        tapController.onTouchEnd();
        dateNowMock.mockReturnValue(tapController.tapTimeMS - 1);
        tapController.onTouchStart(touch);
        tapController.onTouchEnd();
        expect(mockCenterUC.centerOnPixel).toHaveBeenCalledWith(new Vector2(1, 2));
    });
    it("Does no call if too much time has passed", () => {
        const { tapController, mockCenterUC } = makeTestRig();
        const touch = mockTouchInputEvent([new Vector2(1, 2)]);
        const dateNowMock = jest.fn();
        Date.now = dateNowMock;
        dateNowMock.mockReturnValue(0);
        tapController.onTouchStart(touch);
        tapController.onTouchEnd();
        tapController.onTouchStart(touch);
        dateNowMock.mockReturnValue(tapController.tapTimeMS + 1);
        tapController.onTouchEnd();
        expect(mockCenterUC.centerOnPixel).not.toHaveBeenCalled();
    });
    it("Does not count a double tap if there is more than one touch", () => {
        const { tapController, mockCenterUC } = makeTestRig();
        const oneTouch = mockTouchInputEvent([new Vector2(1, 2)]);
        const twoTouch = mockTouchInputEvent([new Vector2(1, 2), Vector2.One()]);
        const dateNowMock = jest.fn();
        Date.now = dateNowMock;
        dateNowMock.mockReturnValue(0);
        tapController.onTouchStart(oneTouch);
        tapController.onTouchEnd();
        tapController.onTouchStart(twoTouch);
        tapController.onTouchEnd();
        expect(mockCenterUC.centerOnPixel).not.toHaveBeenCalled();
    });
    it("Does not count a double tap if the taps are too far apart", () => {
        const { tapController, mockCenterUC } = makeTestRig();
        const tap1 = mockTouchInputEvent([new Vector2(1, 2)]);
        const tap2 = mockTouchInputEvent([
            new Vector2(1, 2 + tapController.maxTapDistancePx + 1),
        ]);
        const dateNowMock = jest.fn();
        Date.now = dateNowMock;
        dateNowMock.mockReturnValue(0);
        tapController.onTouchStart(tap1);
        tapController.onTouchEnd();
        tapController.onTouchStart(tap2);
        tapController.onTouchEnd();
        expect(mockCenterUC.centerOnPixel).not.toHaveBeenCalled();
    });
    it("Does count a double tap if the taps are close enough", () => {
        const { tapController, mockCenterUC } = makeTestRig();
        const tap1 = mockTouchInputEvent([new Vector2(1, 2)]);
        const tap2 = mockTouchInputEvent([
            new Vector2(1, 2 + tapController.maxTapDistancePx),
        ]);
        const dateNowMock = jest.fn();
        Date.now = dateNowMock;
        dateNowMock.mockReturnValue(0);
        tapController.onTouchStart(tap1);
        tapController.onTouchEnd();
        tapController.onTouchStart(tap2);
        tapController.onTouchEnd();
        expect(mockCenterUC.centerOnPixel).toHaveBeenCalled();
    });
});
//# sourceMappingURL=DoubleTapToFocus.test.js.map