"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 DeleteAllLabelDropUC_1 = require("./DeleteAllLabelDropUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const appAO = appObjects.getOrCreate("App");
    const undo = (0, UndoRedoEntity_1.makeUndoRedoEntity)(appObjects.getOrCreate("Undo"));
    const mockDispatchStateChange = (0, MockDispatchStateChange_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    const labelDropAO = appObjects.getOrCreate("repo");
    const repo = (0, LabelDropRepo_1.makeLabelDropRepo)(labelDropAO);
    const dropItem = repo.makeLabelDropItem("id1");
    dropItem.label = "Label";
    dropItem.targetIds = ["obj1"];
    const deleteAllLabelDropUC = (0, DeleteAllLabelDropUC_1.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_1.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