"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 AddCorrectObjectIdUC_1 = require("./AddCorrectObjectIdUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const mockDispatchStateChange = (0, MockDispatchStateChange_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    const objectPick = (0, ObjectPickEntity_1.makeObjectPickEntity)(appObjects.getOrCreate("ObjectPick"));
    const undo = (0, UndoRedoEntity_1.makeUndoRedoEntity)(appObjects.getOrCreate("Undo"));
    const uc = (0, AddCorrectObjectIdUC_1.makeAddCorrectObjectIdUC)(appObjects.getOrCreate("ObjectPick"));
    const addCorrectObjectId = uc.addCorrectObjectId;
    return {
        objectPick,
        addCorrectObjectId,
        doDispatchMock,
        appObjects,
        uc,
        registerSpy,
        undo,
    };
}
describe("Add correct object Id UC", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(AddCorrectObjectIdUC_1.AddCorrectObjectIdUC.get(appObjects)).toEqual(uc);
    });
    it("Registers as the singleton", () => {
        const { registerSpy, uc } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(uc);
    });
    it("Adds correct object Id the entity", () => {
        const { objectPick, addCorrectObjectId } = makeTestRig();
        addCorrectObjectId("id1");
        expect(objectPick.correctObjectIds.includes("id1")).toEqual(true);
    });
    it("Dispatches a state change", () => {
        const { addCorrectObjectId, doDispatchMock } = makeTestRig();
        addCorrectObjectId("id1");
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Is undoable and redoable", () => {
        const { objectPick, addCorrectObjectId, undo } = makeTestRig();
        addCorrectObjectId("id1");
        expect(objectPick.correctObjectIds).toEqual(["id1"]);
        undo.doUndo();
        expect(objectPick.correctObjectIds).toEqual([]);
        undo.doRedo();
        expect(objectPick.correctObjectIds).toEqual(["id1"]);
    });
    it("Undo and redo dispatch a state change", () => {
        const { addCorrectObjectId, undo, doDispatchMock } = makeTestRig();
        addCorrectObjectId("id1");
        doDispatchMock.mockClear();
        undo.doUndo();
        expect(doDispatchMock).toHaveBeenCalled();
        doDispatchMock.mockClear();
        undo.doRedo();
        expect(doDispatchMock).toHaveBeenCalled();
    });
});
//# sourceMappingURL=AddCorrectObjectIdUC.test.js.map