import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { makeUndoRedoEntity } from "../../UndoRedo";
import { makeLandmarkEntity } from "../Entities/LandmarkEntity";
import { makeLandmarkGlobals } from "../Entities/LandmarkGlobals";
import { makeSetLandmarkSizeUC, SetLandmarkSizeUC } from "./SetLandmarkSizeUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const landmarksAO = appObjects.getOrCreate("landmarksGlobals");
    const landmarksGlobals = makeLandmarkGlobals(landmarksAO);
    const landmarkAO = appObjects.getOrCreate("landmarkAO");
    const landmarkEntity = makeLandmarkEntity(landmarkAO);
    const setLandmarkSizeUC = makeSetLandmarkSizeUC(landmarkAO);
    const mockDispatcher = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const undo = 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.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