"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 DeleteCalloutUndoRedo_1 = require("./DeleteCalloutUndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const mockDispatchStateChange = (0, MockDispatchStateChange_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    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;
    repo.deleteCallout("calloutID");
    (0, MockUndoRedo_1.makeMockUndoRedo)(appObjects);
    return {
        doDispatchMock,
        data,
        appObjects,
        repo,
    };
}
describe("Delete Callout Undo Redo", () => {
    it("Undo create callout", () => {
        const { appObjects, data, repo } = makeTestRig();
        expect(repo.hasForAppObject("calloutID")).toEqual(false);
        const action = new DeleteCalloutUndoRedo_1.DeleteCalloutUndoRedo(data, appObjects);
        action.undoAction();
        expect(repo.hasForAppObject("calloutID")).toEqual(true);
    });
    it("Undo applies the data", () => {
        const { appObjects, data, repo } = makeTestRig();
        const action = new DeleteCalloutUndoRedo_1.DeleteCalloutUndoRedo(data, appObjects);
        action.undoAction();
        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("Undo dispatches a state change", () => {
        const { appObjects, doDispatchMock, data } = makeTestRig();
        doDispatchMock.mockClear();
        const action = new DeleteCalloutUndoRedo_1.DeleteCalloutUndoRedo(data, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Redo deletes the callout", () => {
        const { appObjects, repo, data } = makeTestRig();
        const action = new DeleteCalloutUndoRedo_1.DeleteCalloutUndoRedo(data, appObjects);
        action.undoAction();
        expect(repo.hasForAppObject("calloutID")).toEqual(true);
        action.redoAction();
        expect(repo.hasForAppObject("calloutID")).toEqual(false);
    });
    it("Redo dispatches a state change", () => {
        const { appObjects, doDispatchMock, data } = makeTestRig();
        const action = new DeleteCalloutUndoRedo_1.DeleteCalloutUndoRedo(data, appObjects);
        action.undoAction();
        doDispatchMock.mockClear();
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalled();
    });
});
//# sourceMappingURL=DeleteCalloutUndoRedo.test.js.map