import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher/Mocks/MockDispatchStateChange";
import { makeUndoRedoEntity } from "../../UndoRedo/Entities/UndoRedoEntity";
import { makeObjectPickEntity } from "../Entities/ObjectPickEntity";
import { makeRemoveCorrectObjectIdUC, RemoveCorrectObjectIdUC, } from "./RemoveCorrectObjectIdUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const mockDispatchStateChange = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    const undo = makeUndoRedoEntity(appObjects.getOrCreate("Undo"));
    const objectPick = makeObjectPickEntity(appObjects.getOrCreate("ObjectPick"));
    const uc = makeRemoveCorrectObjectIdUC(appObjects.getOrCreate("ObjectPick"));
    const removeCorrectObjectId = uc.removeCorrectObjectId;
    objectPick.addCorrectObjectId("id1");
    return {
        objectPick,
        removeCorrectObjectId,
        doDispatchMock,
        undo,
        registerSpy,
        appObjects,
        uc,
    };
}
describe("Remove correct object Id UC", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(RemoveCorrectObjectIdUC.get(appObjects)).toEqual(uc);
    });
    it("Registers as the singleton", () => {
        const { registerSpy, uc } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(uc);
    });
    it("Removes correct object Id the entity", () => {
        const { objectPick, removeCorrectObjectId } = makeTestRig();
        expect(objectPick.correctObjectIds.includes("id1")).toEqual(true);
        removeCorrectObjectId("id1");
        expect(objectPick.correctObjectIds.includes("id1")).toEqual(false);
    });
    it("Dispatches a state change if authoring", () => {
        const { removeCorrectObjectId, doDispatchMock } = makeTestRig();
        removeCorrectObjectId("id1");
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Is undoable and redoable", () => {
        const { objectPick, removeCorrectObjectId, undo } = makeTestRig();
        removeCorrectObjectId("id1");
        expect(objectPick.correctObjectIds).toEqual([]);
        undo.doUndo();
        expect(objectPick.correctObjectIds).toEqual(["id1"]);
        undo.doRedo();
        expect(objectPick.correctObjectIds).toEqual([]);
    });
    it("Undo and redo dispatch a state change", () => {
        const { removeCorrectObjectId, undo, doDispatchMock } = makeTestRig();
        removeCorrectObjectId("id1");
        doDispatchMock.mockClear();
        undo.doUndo();
        expect(doDispatchMock).toHaveBeenCalled();
        doDispatchMock.mockClear();
        undo.doRedo();
        expect(doDispatchMock).toHaveBeenCalled();
    });
});
//# sourceMappingURL=RemoveCorrectObjectIdUC.test.js.map