"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeTestRig = makeTestRig;
const core_1 = require("@vived/core");
const MouseInput_1 = require("../../../MouseInput");
const TryPanTransformUcMock_1 = require("../../Mocks/TryPanTransformUcMock");
const MousePanTransformMC_1 = require("./MousePanTransformMC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = appObjects.getOrCreate("appObj");
    const mockUC = new TryPanTransformUcMock_1.TryPanTransformUcMock(appObj);
    const input = (0, MouseInput_1.makeMouseInput)(appObj);
    const registerSpy = jest.spyOn(input, "registerController");
    const screenDragController = new MousePanTransformMC_1.MousePanTransformMC(appObj);
    return {
        screenDragController,
        mockUC,
        registerSpy,
    };
}
describe("Screen drag with mouse Controller", () => {
    it("Registers as a controller", () => {
        const { registerSpy, screenDragController } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(screenDragController);
    });
    it("Initializes the try peel", () => {
        const { screenDragController, mockUC } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        screenDragController.onDown(evt);
        expect(mockUC.tryWithPixel).toHaveBeenCalledWith(new core_1.Vector2(2, 3));
    });
    it("Does not initialize Peel if the button is not 0", () => {
        const { screenDragController, mockUC } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        screenDragController.onDown(evt);
        expect(mockUC.tryWithPixel).not.toHaveBeenCalled();
    });
    it("Updates on move if the initializaion was successful", () => {
        const { screenDragController, mockUC } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        mockUC.tryWithPixel.mockReturnValue(true);
        screenDragController.onDown(evt);
        screenDragController.onMove(evt);
        expect(mockUC.moveWithPixel).toHaveBeenCalledWith(new core_1.Vector2(2, 3));
    });
    it("Does not update on move if the initialization was successful", () => {
        const { screenDragController, mockUC } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        mockUC.tryWithPixel.mockReturnValue(false);
        screenDragController.onDown(evt);
        screenDragController.onMove(evt);
        expect(mockUC.moveWithPixel).not.toHaveBeenCalled();
    });
    it("Does not calls initialize on the use case if allow returns false", () => {
        const { mockUC, screenDragController } = makeTestRig();
        screenDragController.allow = () => {
            return false;
        };
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        screenDragController.onDown(evt);
        expect(mockUC.tryWithPixel).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=MousePanTransformMC.test.js.map