"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeTestRig = makeTestRig;
const core_1 = require("@vived/core");
const MockMouseInput_1 = require("../../../MouseInput/Mocks/MockMouseInput");
const MockPanTransformUC_1 = require("../../Mocks/MockPanTransformUC");
const PanTransformMC_1 = require("./PanTransformMC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appAO = appObjects.getOrCreate("AO");
    const mockPan = new MockPanTransformUC_1.MockPanTransformUC(appAO);
    const mockMouseInput = new MockMouseInput_1.MockMouseInput(appObjects.getOrCreate("MouseController"));
    const panController = new PanTransformMC_1.PanTransformMC(appAO);
    return { mockMouseInput, panController, mockPan };
}
describe("Mouse Pan Controller", () => {
    it("Initializes Pan if the button is 1", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onDown(evt);
        expect(mockPan.initializePixel).toHaveBeenCalledWith(new core_1.Vector2(2, 3));
    });
    it("Initializes Pan if allow is set to true", () => {
        const { panController, mockPan } = makeTestRig();
        panController.allow = () => {
            return true;
        };
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        panController.onDown(evt);
        expect(mockPan.initializePixel).toHaveBeenCalledWith(new core_1.Vector2(2, 3));
    });
    it("Does not initializes Pan if allow return false", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        panController.allow = () => {
            return false;
        };
        panController.onDown(evt);
        expect(mockPan.initializePixel).not.toHaveBeenCalled();
    });
    it("Sends a Pan if it was initialized", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onDown(evt);
        evt.position = new core_1.Vector2(4, 5);
        panController.onMove(evt);
        expect(mockPan.updatePixel).toHaveBeenCalledWith(new core_1.Vector2(4, 5));
    });
    it("Does not send a Pan if it was notinitialized", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onMove(evt);
        expect(mockPan.updatePixel).not.toHaveBeenCalled();
    });
    it("Finishes the pan", () => {
        const { panController, mockPan } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        panController.onDown(evt);
        panController.onUp();
        expect(mockPan.finish).toHaveBeenCalled();
    });
});
//# sourceMappingURL=PanTransformMC.test.js.map