"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockDispatchStateChange_1 = require("../../Dispatcher/Mocks/MockDispatchStateChange");
const OverlayColor_1 = require("../../OverlayColor/Entities/OverlayColor");
const MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const CalloutRepo_1 = require("../Entities/CalloutRepo");
const CreateCalloutUndoRedo_1 = require("./CreateCalloutUndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const mockDispatchStateChange = (0, MockDispatchStateChange_1.makeMockDispatchStateChange)(appObjects);
    const repoAO = appObjects.getOrCreate("repoID");
    const repo = (0, CalloutRepo_1.makeCalloutRepoEntity)(repoAO);
    const newCallout = repo.makeCallout("calloutID");
    newCallout.rootPosition = new core_1.Vector3(1, 2, 3);
    newCallout.rootRotation = core_1.Quaternion.FromAngleAxis(new core_1.Vector3(1, 2, 3), core_1.Angle.FromDegrees(12));
    newCallout.size = 1.23;
    newCallout.overlayColor.overlayColor = OverlayColor_1.OverlayColorEnums.PINK;
    const data = newCallout.data;
    (0, MockUndoRedo_1.makeMockUndoRedo)(appObjects);
    return {
        mockDispatchStateChange,
        data,
        appObjects,
        repo,
    };
}
describe("Create Callout Undo Redo", () => {
    it("Undo deletes the callout", () => {
        const { appObjects, repo, data } = makeTestRig();
        expect(repo.hasForAppObject("calloutID")).toEqual(true);
        const action = new CreateCalloutUndoRedo_1.CreateCalloutUndoRedo(data, appObjects);
        action.undoAction();
        expect(repo.hasForAppObject("calloutID")).toEqual(false);
    });
    it("Undo dispatches a state change", () => {
        const { appObjects, mockDispatchStateChange, data } = makeTestRig();
        const mockDoDispatch = jest.fn();
        mockDispatchStateChange.doDispatch = mockDoDispatch;
        const action = new CreateCalloutUndoRedo_1.CreateCalloutUndoRedo(data, appObjects);
        action.undoAction();
        expect(mockDoDispatch).toHaveBeenCalled();
    });
    it("Redoes create callout", () => {
        const { appObjects, data, repo } = makeTestRig();
        const action = new CreateCalloutUndoRedo_1.CreateCalloutUndoRedo(data, appObjects);
        action.undoAction();
        expect(repo.hasForAppObject("calloutID")).toEqual(false);
        action.redoAction();
        expect(repo.hasForAppObject("calloutID")).toEqual(true);
    });
    it("Redoes applies the data", () => {
        const { appObjects, data, repo } = makeTestRig();
        const action = new CreateCalloutUndoRedo_1.CreateCalloutUndoRedo(data, appObjects);
        action.undoAction();
        action.redoAction();
        const callout = repo.getForAppObject("calloutID");
        expect(callout?.data.color).toEqual(data.color);
        expect(callout?.data.size).toEqual(data.size);
        expect(callout?.data.rootPosition).toEqual(data.rootPosition);
    });
    it("Redo dispatches a state change", () => {
        const { appObjects, mockDispatchStateChange, data } = makeTestRig();
        const mockDoDispatch = jest.fn();
        mockDispatchStateChange.doDispatch = mockDoDispatch;
        const action = new CreateCalloutUndoRedo_1.CreateCalloutUndoRedo(data, appObjects);
        action.undoAction();
        mockDoDispatch.mockClear();
        action.redoAction();
        expect(mockDoDispatch).toHaveBeenCalled();
    });
});
//# sourceMappingURL=CreateCalloutUndoRedo.test.js.map