"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockDispatchStateChange_1 = require("../../Dispatcher/Mocks/MockDispatchStateChange");
const UndoRedoEntity_1 = require("../../UndoRedo/Entities/UndoRedoEntity");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
const DeleteLabelDropUC_1 = require("./DeleteLabelDropUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const undo = (0, UndoRedoEntity_1.makeUndoRedoEntity)(appObjects.getOrCreate("Undo"));
    const mockDispatchStateChange = (0, MockDispatchStateChange_1.makeMockDispatchStateChange)(appObjects);
    const labelDropAO = appObjects.getOrCreate("repo");
    const repo = (0, LabelDropRepo_1.makeLabelDropRepo)(labelDropAO);
    const dropItem = repo.makeLabelDropItem("id1");
    dropItem.label = "Label";
    dropItem.targetIds = ["obj1"];
    const deleteLabelDropUC = (0, DeleteLabelDropUC_1.makeDeleteLabelDropUC)(labelDropAO);
    return {
        appObjects,
        repo,
        deleteLabelDropUC,
        registerSpy,
        mockDispatchStateChange,
        undo,
        dropItem,
    };
}
describe("Delete Label drop UC", () => {
    it("Get it UC", () => {
        const { appObjects, deleteLabelDropUC } = makeTestRig();
        expect(DeleteLabelDropUC_1.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, mockDispatchStateChange } = makeTestRig();
        deleteLabelDropUC.deleteLabelDrop("id1");
        expect(mockDispatchStateChange.doDispatch).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, mockDispatchStateChange, repo } = makeTestRig();
        deleteLabelDropUC.deleteLabelDrop("id1");
        expect(repo.hasForAppObject("id1")).toEqual(false);
        mockDispatchStateChange.doDispatch.mockClear();
        undo.doUndo();
        expect(repo.hasForAppObject("id1")).toEqual(true);
        expect(repo.getForAppObject("id1")?.label).toEqual("Label");
        expect(repo.getForAppObject("id1")?.targetIds).toEqual(["obj1"]);
        expect(mockDispatchStateChange.doDispatch).toHaveBeenCalledTimes(1);
        undo.doRedo();
        expect(repo.hasForAppObject("id1")).toEqual(false);
        expect(mockDispatchStateChange.doDispatch).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=DeleteLabelDropUC.test.js.map