"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 ObjectPickEntity_1 = require("../Entities/ObjectPickEntity");
const ClearCorrectObjectIdsUC_1 = require("./ClearCorrectObjectIdsUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const mockDispatchStateChange = (0, MockDispatchStateChange_1.makeMockDispatchStateChange)(appObjects);
    const undo = (0, UndoRedoEntity_1.makeUndoRedoEntity)(appObjects.getOrCreate("Undo"));
    const objectPick = (0, ObjectPickEntity_1.makeObjectPickEntity)(appObjects.getOrCreate("ObjectPick"));
    const uc = (0, ClearCorrectObjectIdsUC_1.makeClearCorrectObjectIdsUC)(appObjects.getOrCreate("ObjectPick"));
    const clearCorrectObjectIds = uc.clearCorrectObjectIds;
    objectPick.addCorrectObjectId("id1");
    objectPick.addCorrectObjectId("id2");
    return {
        objectPick,
        clearCorrectObjectIds,
        mockDispatchStateChange,
        registerSpy,
        appObjects,
        uc,
        undo,
    };
}
describe("Clear correct object Id UC", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(ClearCorrectObjectIdsUC_1.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, mockDispatchStateChange } = makeTestRig();
        clearCorrectObjectIds();
        expect(mockDispatchStateChange.doDispatch).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, mockDispatchStateChange } = makeTestRig();
        clearCorrectObjectIds();
        mockDispatchStateChange.doDispatch.mockClear();
        undo.doUndo();
        expect(mockDispatchStateChange.doDispatch).toHaveBeenCalled();
        mockDispatchStateChange.doDispatch.mockClear();
        undo.doRedo();
        expect(mockDispatchStateChange.doDispatch).toHaveBeenCalled();
    });
});
//# sourceMappingURL=ClearCorrectObjectIdsUC.test.js.map