import { makeAppObjectRepo, Vector2 } from "@vived/core";
import { MockTouchInputEntity } from "../../../TouchController/Mock/MockTouchInput";
import { mockTouchInputEvent } from "../../../TouchController/Mock/mockTouchInputEvent";
import { MockPanTransformUC } from "../../Mocks/MockPanTransformUC";
import { PanTransformTC } from "./PanTransformTC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("app");
    new MockTouchInputEntity(app);
    const appObj = appObjects.getOrCreate("AO");
    const mockPan = new MockPanTransformUC(appObj);
    const panController = new 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 = mockTouchInputEvent([new Vector2(0, 0), new Vector2(79, 0)]);
        panController.onTouchStart(input);
        expect(mockPan.initializePixel).toHaveBeenCalledWith(new Vector2(39.5, 0));
    });
    it("Does not initialize if allow return false", () => {
        const { panController, mockPan } = makeTestRig();
        panController.allow = () => {
            return false;
        };
        const input = mockTouchInputEvent([new Vector2(0, 0), new 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 = mockTouchInputEvent([new Vector2(0, 0)]);
        panController.onTouchStart(startInput);
        const moveInput = mockTouchInputEvent([new Vector2(-50, 0)]);
        panController.onTouchMove(moveInput);
        expect(mockPan.updatePixel).toHaveBeenCalledWith(new Vector2(-50, 0));
    });
    it("Does not send Pan if not initialized", () => {
        const { panController, mockPan } = makeTestRig();
        const moveInput = mockTouchInputEvent([new Vector2(-50, 0)]);
        panController.onTouchMove(moveInput);
        expect(mockPan.updatePixel).not.toHaveBeenCalled();
    });
    it("Finalizes the pan", () => {
        const { panController, mockPan } = makeTestRig();
        const startInput = mockTouchInputEvent([new Vector2(0, 0)]);
        panController.onTouchStart(startInput);
        const endInput = mockTouchInputEvent([new 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 = mockTouchInputEvent([new Vector2(50, 0)]);
        panController.onTouchStart(startInput);
        const moveInput = mockTouchInputEvent([new Vector2(40, 0)]);
        panController.onTouchMove(moveInput);
        expect(mockPan.updatePixel).toHaveBeenCalledWith(new Vector2(40, 0));
        mockPan.updatePixel.mockClear();
        panController.allow = () => {
            return false;
        };
        const startInput2 = mockTouchInputEvent([
            new Vector2(0, 0),
            new Vector2(85, 0),
        ]);
        panController.onTouchStart(startInput2);
        const moveInput2 = mockTouchInputEvent([new Vector2(-50, 0)]);
        panController.onTouchMove(moveInput2);
        expect(mockPan.updatePixel).not.toHaveBeenCalled();
        expect(mockPan.cancelPan).toHaveBeenCalled();
    });
});
//# sourceMappingURL=PanTransformTC.test.js.map