import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { makeUndoRedoEntity } from "../../UndoRedo/Entities/UndoRedoEntity";
import { makeCalloutEntity } from "../Entities/CalloutEntity";
import { makeCalloutGlobals } from "../Entities/CalloutGlobals";
import { makeSetCalloutSizeUC, SetCalloutSizeUC } from "./SetCalloutSizeUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const globalAO = appObjects.getOrCreate("calloutsGlobals");
    const calloutsGlobals = makeCalloutGlobals(globalAO);
    const ao = appObjects.getOrCreate("calloutAO");
    const calloutEntity = makeCalloutEntity(ao);
    const uc = makeSetCalloutSizeUC(ao);
    const mockDispatcher = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const undo = makeUndoRedoEntity(appObjects.getOrCreate("Undo"));
    return {
        calloutEntity,
        calloutsGlobals,
        uc,
        mockDispatcher,
        doDispatchMock,
        undo,
        appObjects,
    };
}
describe("Set Landmark Size UC", () => {
    it("Gets the UC", () => {
        const { appObjects, uc } = makeTestRig();
        expect(SetCalloutSizeUC.getById("calloutAO", appObjects)).toEqual(uc);
    });
    it("Updates the size with updateSize method", () => {
        const { calloutEntity, uc } = makeTestRig();
        uc.updateSize(0.5);
        expect(calloutEntity.size).toEqual(0.5);
    });
    it("Updates the size with submitSize method", () => {
        const { calloutEntity, uc } = makeTestRig();
        uc.updateSize(0.4);
        uc.submitSize(0.5);
        expect(calloutEntity.size).toEqual(0.5);
    });
    it("Sets the last size of calloutsGlobals with submitSize method", () => {
        const { calloutsGlobals, uc } = makeTestRig();
        uc.updateSize(0.4);
        uc.submitSize(0.8);
        expect(calloutsGlobals.lastSize).toEqual(0.8);
        uc.updateSize(0.4);
        uc.submitSize(0.7);
        expect(calloutsGlobals.lastSize).toEqual(0.7);
    });
    it("Dispatches a state change with submitSize method", () => {
        const { doDispatchMock, uc } = makeTestRig();
        uc.updateSize(0.5);
        uc.submitSize(0.6);
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Is undo able and redo able", () => {
        const { undo, uc, calloutEntity } = makeTestRig();
        calloutEntity.size = 1;
        uc.updateSize(1.1);
        uc.submitSize(1.2);
        expect(calloutEntity.size).toEqual(1.2);
        undo.doUndo();
        expect(calloutEntity.size).toEqual(1);
        undo.doRedo();
        expect(calloutEntity.size).toEqual(1.2);
    });
});
//# sourceMappingURL=SetCalloutSizeUC.test.js.map