"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockTouchInput_1 = require("../../../TouchController/Mock/MockTouchInput");
const mockTouchInputEvent_1 = require("../../../TouchController/Mock/mockTouchInputEvent");
const MockPanTransformUC_1 = require("../../Mocks/MockPanTransformUC");
const PanTransformTC_1 = require("./PanTransformTC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const app = appObjects.getOrCreate("app");
    new MockTouchInput_1.MockTouchInputEntity(app);
    const appObj = appObjects.getOrCreate("AO");
    const mockPan = new MockPanTransformUC_1.MockPanTransformUC(appObj);
    const panController = new PanTransformTC_1.PanTransformTC(appObj);
    return { panController, mockPan };
}
describe("Touch Pan Controller", () => {
    it("Initializes if allow return true", () => {
        const { panController, mockPan } = makeTestRig();
        panController.allow = () => {
            return true;
        };
        const input = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(0, 0), new core_1.Vector2(79, 0)]);
        panController.onTouchStart(input);
        expect(mockPan.initializePixel).toHaveBeenCalledWith(new core_1.Vector2(39.5, 0));
    });
    it("Does not initialize if allow return false", () => {
        const { panController, mockPan } = makeTestRig();
        panController.allow = () => {
            return false;
        };
        const input = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(0, 0), new core_1.Vector2(79, 0)]);
        panController.onTouchStart(input);
        expect(mockPan.initializePixel).not.toHaveBeenCalled();
    });
    it("Sends updates the Pan if the fingers move after initialization", () => {
        const { panController, mockPan } = makeTestRig();
        const startInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(0, 0)]);
        panController.onTouchStart(startInput);
        const moveInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(-50, 0)]);
        panController.onTouchMove(moveInput);
        expect(mockPan.updatePixel).toHaveBeenCalledWith(new core_1.Vector2(-50, 0));
    });
    it("Does not send Pan if not initialized", () => {
        const { panController, mockPan } = makeTestRig();
        const moveInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(-50, 0)]);
        panController.onTouchMove(moveInput);
        expect(mockPan.updatePixel).not.toHaveBeenCalled();
    });
    it("Finalizes the pan", () => {
        const { panController, mockPan } = makeTestRig();
        const startInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(0, 0)]);
        panController.onTouchStart(startInput);
        const endInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(-50, 0)]);
        panController.onTouchEnd(endInput);
        expect(mockPan.finish).toHaveBeenCalled();
    });
    it("Cancels orbit if the allow changes it's response", () => {
        const { panController, mockPan } = makeTestRig();
        const startInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(50, 0)]);
        panController.onTouchStart(startInput);
        const moveInput = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(40, 0)]);
        panController.onTouchMove(moveInput);
        expect(mockPan.updatePixel).toHaveBeenCalledWith(new core_1.Vector2(40, 0));
        mockPan.updatePixel.mockClear();
        panController.allow = () => {
            return false;
        };
        const startInput2 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([
            new core_1.Vector2(0, 0),
            new core_1.Vector2(85, 0),
        ]);
        panController.onTouchStart(startInput2);
        const moveInput2 = (0, mockTouchInputEvent_1.mockTouchInputEvent)([new core_1.Vector2(-50, 0)]);
        panController.onTouchMove(moveInput2);
        expect(mockPan.updatePixel).not.toHaveBeenCalled();
        expect(mockPan.cancelPan).toHaveBeenCalled();
    });
});
//# sourceMappingURL=PanTransformTC.test.js.map