import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher/Mocks/MockDispatchStateChange";
import { makeUndoRedoEntity } from "../../UndoRedo/Entities/UndoRedoEntity";
import { makeLabelDropRepo } from "../Entities/LabelDropRepo";
import { DeleteAllLabelDropUC, makeDeleteAllLabelDropUC, } from "./DeleteAllLabelDropUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appAO = appObjects.getOrCreate("App");
    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 deleteAllLabelDropUC = makeDeleteAllLabelDropUC(labelDropAO);
    return {
        appAO,
        appObjects,
        undo,
        repo,
        deleteAllLabelDropUC,
        doDispatchMock,
        registerSpy,
    };
}
describe("Delete All Label Drop Answer Items Use Cases", () => {
    it("Get it UC", () => {
        const { appObjects, deleteAllLabelDropUC } = makeTestRig();
        expect(DeleteAllLabelDropUC.get(appObjects)).toEqual(deleteAllLabelDropUC);
    });
    it("Registers as the singleton", () => {
        const { deleteAllLabelDropUC, registerSpy } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(deleteAllLabelDropUC);
    });
    it("Deletes all Label Drop Answer Items", () => {
        const { deleteAllLabelDropUC, repo } = makeTestRig();
        expect(repo.getAll().length).toEqual(1);
        deleteAllLabelDropUC.delete();
        expect(repo.getAll().length).toEqual(0);
    });
    it("Dispatches state change", () => {
        const { deleteAllLabelDropUC, doDispatchMock } = makeTestRig();
        deleteAllLabelDropUC.delete();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Can undo and redo the delete", () => {
        const { deleteAllLabelDropUC, undo, doDispatchMock, repo } = makeTestRig();
        deleteAllLabelDropUC.delete();
        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=DeleteAllLabelDropUC.test.js.map