import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher/Mocks/MockDispatchStateChange";
import { makeUndoRedoEntity } from "../../UndoRedo/Entities/UndoRedoEntity";
import { makeObjectPickEntity } from "../Entities/ObjectPickEntity";
import { makeClearCorrectObjectIdsUC, ClearCorrectObjectIdsUC, } from "./ClearCorrectObjectIdsUC";
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 = makeClearCorrectObjectIdsUC(appObjects.getOrCreate("ObjectPick"));
    const clearCorrectObjectIds = uc.clearCorrectObjectIds;
    objectPick.addCorrectObjectId("id1");
    objectPick.addCorrectObjectId("id2");
    return {
        objectPick,
        clearCorrectObjectIds,
        doDispatchMock,
        registerSpy,
        appObjects,
        uc,
        undo,
    };
}
describe("Clear correct object Id UC", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(ClearCorrectObjectIdsUC.get(appObjects)).toEqual(uc);
    });
    it("Registers as the singleton", () => {
        const { registerSpy, uc } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(uc);
    });
    it("Clears correct object Id the entity", () => {
        const { objectPick, clearCorrectObjectIds } = makeTestRig();
        expect(objectPick.correctObjectIds.length).toEqual(2);
        clearCorrectObjectIds();
        expect(objectPick.correctObjectIds.length).toEqual(0);
    });
    it("Dispatches a state change", () => {
        const { clearCorrectObjectIds, doDispatchMock } = makeTestRig();
        clearCorrectObjectIds();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Is undoable and redoable", () => {
        const { objectPick, clearCorrectObjectIds, undo } = makeTestRig();
        expect(objectPick.correctObjectIds).toEqual(["id1", "id2"]);
        clearCorrectObjectIds();
        expect(objectPick.correctObjectIds).toEqual([]);
        undo.doUndo();
        expect(objectPick.correctObjectIds).toEqual(["id1", "id2"]);
        undo.doRedo();
        expect(objectPick.correctObjectIds).toEqual([]);
    });
    it("Undo and redo dispatch a state change", () => {
        const { clearCorrectObjectIds, undo, doDispatchMock } = makeTestRig();
        clearCorrectObjectIds();
        doDispatchMock.mockClear();
        undo.doUndo();
        expect(doDispatchMock).toHaveBeenCalled();
        doDispatchMock.mockClear();
        undo.doRedo();
        expect(doDispatchMock).toHaveBeenCalled();
    });
});
//# sourceMappingURL=ClearCorrectObjectIdsUC.test.js.map