"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const UndoRedo_1 = require("../../UndoRedo");
const LandmarkEntity_1 = require("../Entities/LandmarkEntity");
const LandmarkGlobals_1 = require("../Entities/LandmarkGlobals");
const SetLandmarkSizeUC_1 = require("./SetLandmarkSizeUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const landmarksAO = appObjects.getOrCreate("landmarksGlobals");
    const landmarksGlobals = (0, LandmarkGlobals_1.makeLandmarkGlobals)(landmarksAO);
    const landmarkAO = appObjects.getOrCreate("landmarkAO");
    const landmarkEntity = (0, LandmarkEntity_1.makeLandmarkEntity)(landmarkAO);
    const setLandmarkSizeUC = (0, SetLandmarkSizeUC_1.makeSetLandmarkSizeUC)(landmarkAO);
    const mockDispatcher = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const undo = (0, UndoRedo_1.makeUndoRedoEntity)(appObjects.getOrCreate("Undo"));
    return {
        landmarkEntity,
        landmarksGlobals,
        setLandmarkSizeUC,
        mockDispatcher,
        doDispatchMock,
        undo,
        appObjects,
    };
}
describe("Set Landmark Size UC", () => {
    it("Gets the UC", () => {
        const { appObjects, setLandmarkSizeUC } = makeTestRig();
        expect(SetLandmarkSizeUC_1.SetLandmarkSizeUC.getById("landmarkAO", appObjects)).toEqual(setLandmarkSizeUC);
    });
    it("Updates the size with updateSize method", () => {
        const { landmarkEntity, setLandmarkSizeUC } = makeTestRig();
        setLandmarkSizeUC.updateSize(0.5);
        expect(landmarkEntity.size).toEqual(0.5);
    });
    it("Updates the size with submitSize method", () => {
        const { landmarkEntity, setLandmarkSizeUC } = makeTestRig();
        setLandmarkSizeUC.updateSize(0.4);
        setLandmarkSizeUC.submitSize(0.5);
        expect(landmarkEntity.size).toEqual(0.5);
    });
    it("Sets the last size of landmarksGlobals with submitSize method", () => {
        const { landmarksGlobals, setLandmarkSizeUC } = makeTestRig();
        setLandmarkSizeUC.updateSize(0.4);
        setLandmarkSizeUC.submitSize(0.8);
        expect(landmarksGlobals.lastSize).toEqual(0.8);
        setLandmarkSizeUC.updateSize(0.4);
        setLandmarkSizeUC.submitSize(0.7);
        expect(landmarksGlobals.lastSize).toEqual(0.7);
    });
    it("Dispatches a state change with submitSize method", () => {
        const { doDispatchMock, setLandmarkSizeUC } = makeTestRig();
        setLandmarkSizeUC.updateSize(0.5);
        setLandmarkSizeUC.submitSize(0.8);
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Is undo able and redo able", () => {
        const { undo, setLandmarkSizeUC, landmarkEntity } = makeTestRig();
        landmarkEntity.size = 1;
        setLandmarkSizeUC.updateSize(1.1);
        setLandmarkSizeUC.submitSize(1.2);
        expect(landmarkEntity.size).toEqual(1.2);
        undo.doUndo();
        expect(landmarkEntity.size).toEqual(1);
        undo.doRedo();
        expect(landmarkEntity.size).toEqual(1.2);
    });
});
//# sourceMappingURL=SetLandmarkSizeUC.test.js.map