"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MouseInput_1 = require("../../MouseInput/Entities/MouseInput");
const TryAddCalloutMock_1 = require("../Mocks/TryAddCalloutMock");
const MouseAddCalloutMC_1 = require("./MouseAddCalloutMC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const mouseInput = (0, MouseInput_1.makeMouseInput)(appObjects.getOrCreate("Input"));
    const registerSpy = jest.spyOn(mouseInput, "registerController");
    const addMock = (0, TryAddCalloutMock_1.makeTryAddCalloutMock)(appObjects);
    addMock.initializeWithPixel.mockReturnValue(true);
    const controller = new MouseAddCalloutMC_1.MouseAddCalloutMC(appObjects.getOrCreate("AO"));
    return {
        registerSpy,
        controller,
        addMock,
    };
}
describe("MouseCallout Controller Test", () => {
    it("Registers with the mouse input when constructed", () => {
        const { registerSpy, controller } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(controller);
    });
    it("Initializes the UC when the tool is Callout a button is 0", () => {
        const { controller, addMock } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt);
        expect(addMock.initializeWithPixel).toHaveBeenCalledWith(new core_1.Vector2(2, 3));
    });
    it("Does not initialize if button is not 0", () => {
        const { controller, addMock } = makeTestRig();
        const evt = {
            position: new core_1.Vector2(2, 3),
            button: 1,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt);
        expect(addMock.initializeWithPixel).not.toHaveBeenCalled();
    });
    it("Moving updates after a successful down", () => {
        const { controller, addMock } = makeTestRig();
        const evt1 = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt1);
        const evt2 = {
            position: new core_1.Vector2(4, 5),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onMove(evt2);
        expect(addMock.moveWithPixel).toHaveBeenCalledWith(new core_1.Vector2(4, 5));
    });
    it("Moving does not updates without a down", () => {
        const { controller, addMock } = makeTestRig();
        const evt2 = {
            position: new core_1.Vector2(4, 5),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onMove(evt2);
        expect(addMock.moveWithPixel).not.toHaveBeenCalled();
    });
    it("Stop updates after a successful down", () => {
        const { controller, addMock } = makeTestRig();
        const evt1 = {
            position: new core_1.Vector2(2, 3),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onDown(evt1);
        controller.onUp(evt1);
        expect(addMock.stop).toHaveBeenCalled();
    });
    it("Stop does not updates without a down", () => {
        const { controller, addMock } = makeTestRig();
        const evt2 = {
            position: new core_1.Vector2(4, 5),
            button: 0,
            event: new MouseEvent("buttondown"),
        };
        controller.onUp(evt2);
        expect(addMock.stop).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=MouseAddCalloutMC.test.js.map