import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { makeUndoRedoEntity } from "../../UndoRedo";
import { makeLandmarkRepoEntity } from "../Entities/LandmarkRepo";
import { makeDeleteAllLandmarksUC } from "./DeleteAllLandmarksUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const mockDispatcher = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const deleteAllLandmarksUC = makeDeleteAllLandmarksUC(appObjects.getOrCreate("Landmarks"));
    const repo1 = makeLandmarkRepoEntity(appObjects.getOrCreate("parent1"));
    const repo2 = makeLandmarkRepoEntity(appObjects.getOrCreate("parent2"));
    repo1.createLandmark("landmark1");
    repo2.createLandmark("landmark2");
    const undo = makeUndoRedoEntity(appObjects.getOrCreate("Undo"));
    return {
        repo1,
        repo2,
        deleteAllLandmarksUC,
        doDispatchMock,
        undo,
    };
}
describe("Delete All Landmarks UC", () => {
    it("Deletes all Landmarks UC", () => {
        const { deleteAllLandmarksUC, repo1, repo2 } = makeTestRig();
        deleteAllLandmarksUC.deleteAllLandmarks();
        expect(repo1.getAll().length).toEqual(0);
        expect(repo2.getAll().length).toEqual(0);
    });
    it("Dispatches state change", () => {
        const { deleteAllLandmarksUC, doDispatchMock } = makeTestRig();
        deleteAllLandmarksUC.deleteAllLandmarks();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Is undoable and redoable", () => {
        const { deleteAllLandmarksUC, repo1, repo2, undo } = makeTestRig();
        deleteAllLandmarksUC.deleteAllLandmarks();
        expect(repo1.getAll().length).toEqual(0);
        expect(repo2.getAll().length).toEqual(0);
        undo.doUndo();
        expect(repo1.getAll().length).toEqual(1);
        expect(repo2.getAll().length).toEqual(1);
        undo.doRedo();
        expect(repo1.getAll().length).toEqual(0);
        expect(repo2.getAll().length).toEqual(0);
    });
});
//# sourceMappingURL=DeleteAllLandmarksUC.test.js.map