import { Angle, makeAppObjectRepo, Quaternion, Vector3 } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher/Mocks/MockDispatchStateChange";
import { OverlayColorEnums } from "../../OverlayColor/Entities/OverlayColor";
import { makeMockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeCalloutRepoEntity } from "../Entities/CalloutRepo";
import { CreateCalloutUndoRedo } from "./CreateCalloutUndoRedo";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const mockDispatchStateChange = makeMockDispatchStateChange(appObjects);
    const repoAO = appObjects.getOrCreate("repoID");
    const repo = makeCalloutRepoEntity(repoAO);
    const newCallout = repo.makeCallout("calloutID");
    newCallout.rootPosition = new Vector3(1, 2, 3);
    newCallout.rootRotation = Quaternion.FromAngleAxis(new Vector3(1, 2, 3), Angle.FromDegrees(12));
    newCallout.size = 1.23;
    newCallout.overlayColor.overlayColor = OverlayColorEnums.PINK;
    const data = newCallout.data;
    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(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(data, appObjects);
        action.undoAction();
        expect(mockDoDispatch).toHaveBeenCalled();
    });
    it("Redoes create callout", () => {
        const { appObjects, data, repo } = makeTestRig();
        const action = new 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(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(data, appObjects);
        action.undoAction();
        mockDoDispatch.mockClear();
        action.redoAction();
        expect(mockDoDispatch).toHaveBeenCalled();
    });
});
//# sourceMappingURL=CreateCalloutUndoRedo.test.js.map