import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher/Mocks/MockDispatchStateChange";
import { makeUndoRedoEntity } from "../../UndoRedo/Entities/UndoRedoEntity";
import { makeLabelDropRepo } from "../Entities/LabelDropRepo";
import { DeleteLabelDropUC, makeDeleteLabelDropUC } from "./DeleteLabelDropUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const undo = makeUndoRedoEntity(appObjects.getOrCreate("Undo"));
    const mockDispatchStateChange = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    const labelDropAO = appObjects.getOrCreate("repo");
    const repo = makeLabelDropRepo(labelDropAO);
    const dropItem = repo.makeLabelDropItem("id1");
    dropItem.label = "Label";
    dropItem.targetIds = ["obj1"];
    const deleteLabelDropUC = makeDeleteLabelDropUC(labelDropAO);
    return {
        appObjects,
        repo,
        deleteLabelDropUC,
        registerSpy,
        doDispatchMock,
        undo,
        dropItem,
    };
}
describe("Delete Label drop UC", () => {
    it("Get it UC", () => {
        const { appObjects, deleteLabelDropUC } = makeTestRig();
        expect(DeleteLabelDropUC.get(appObjects)).toEqual(deleteLabelDropUC);
    });
    it("Registers as the singleton", () => {
        const { deleteLabelDropUC, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(deleteLabelDropUC);
    });
    it("Deletes a label drop", () => {
        const { repo, deleteLabelDropUC } = makeTestRig();
        const spy = jest.spyOn(repo, "deleteItem");
        deleteLabelDropUC.deleteLabelDrop("id1");
        expect(spy).toHaveBeenCalledWith("id1");
    });
    it("Dispatches a state change", () => {
        const { deleteLabelDropUC, doDispatchMock } = makeTestRig();
        deleteLabelDropUC.deleteLabelDrop("id1");
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Clears the editing id", () => {
        const { deleteLabelDropUC, repo } = makeTestRig();
        repo.editingID = "id1";
        deleteLabelDropUC.deleteLabelDrop("id1");
        expect(repo.editingID).toBeUndefined();
    });
    it("Can undo and redo the delete", () => {
        const { deleteLabelDropUC, undo, doDispatchMock, repo } = makeTestRig();
        deleteLabelDropUC.deleteLabelDrop("id1");
        expect(repo.hasForAppObject("id1")).toEqual(false);
        doDispatchMock.mockClear();
        undo.doUndo();
        expect(repo.hasForAppObject("id1")).toEqual(true);
        expect(repo.getForAppObject("id1")?.label).toEqual("Label");
        expect(repo.getForAppObject("id1")?.targetIds).toEqual(["obj1"]);
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        undo.doRedo();
        expect(repo.hasForAppObject("id1")).toEqual(false);
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=DeleteLabelDropUC.test.js.map