"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const MockTouchInput_1 = require("../../TouchController/Mock/MockTouchInput");
const mockTouchInputEvent_1 = require("../../TouchController/Mock/mockTouchInputEvent");
const MockFocusOnPixelUC_1 = require("../Mocks/MockFocusOnPixelUC");
const DoubleTapToFocus_1 = require("./DoubleTapToFocus");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const app = appObjects.getOrCreate("app");
    new MockTouchInput_1.MockTouchInputEntity(app);
    const appAO = appObjects.getOrCreate("AO");
    const mockCenterUC = new MockFocusOnPixelUC_1.MockFocusOnPixelUC(appAO);
    const tapController = new DoubleTapToFocus_1.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 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.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 core_2.Vector2(1, 2));
    });
    it("Does no call if too much time has passed", () => {
        const { tapController, mockCenterUC } = makeTestRig();
        const touch = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.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 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.Vector2(1, 2)]);
        const twoTouch = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.Vector2(1, 2), core_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 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.Vector2(1, 2)]);
        const tap2 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([
            new core_2.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 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_2.Vector2(1, 2)]);
        const tap2 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([
            new core_2.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