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 { DeleteCalloutUndoRedo } from "./DeleteCalloutUndoRedo";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const mockDispatchStateChange = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    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;
    repo.deleteCallout("calloutID");
    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(data, appObjects);
        action.undoAction();
        expect(repo.hasForAppObject("calloutID")).toEqual(true);
    });
    it("Undo applies the data", () => {
        const { appObjects, data, repo } = makeTestRig();
        const action = new 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(data, appObjects);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Redo deletes the callout", () => {
        const { appObjects, repo, data } = makeTestRig();
        const action = new 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(data, appObjects);
        action.undoAction();
        doDispatchMock.mockClear();
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalled();
    });
});
//# sourceMappingURL=DeleteCalloutUndoRedo.test.js.map