import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeLabelEntity } from "../Entities";
import { SetCustomLabelUndoRedo } from "./SetCustomLabelUndoRedo";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("App");
    const mockUndo = new MockUndoRedo(ao);
    // Override the submitAction with a jest.fn()
    mockUndo.submitAction = jest.fn();
    const mockDispatcher = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const label = makeLabelEntity(ao);
    return { mockUndo, mockDispatcher, doDispatchMock, label, ao };
}
describe("Set Custom Label Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, ao } = makeTestRig();
        const action = new SetCustomLabelUndoRedo("prevLabel", "curLabel", ao);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo sets the prior custom label ", () => {
        const { ao, label } = makeTestRig();
        const prevLabel = "prevLabel";
        const curLabel = "curLabel";
        label.custom = curLabel;
        const action = new SetCustomLabelUndoRedo(prevLabel, curLabel, ao);
        action.undoAction();
        expect(label.custom).toEqual(prevLabel);
    });
    it("Redo sets the current label ", () => {
        const { ao, label } = makeTestRig();
        const prevLabel = "prevLabel";
        const curLabel = "curLabel";
        label.custom = curLabel;
        const action = new SetCustomLabelUndoRedo(prevLabel, curLabel, ao);
        action.undoAction();
        action.redoAction();
        expect(label.custom).toEqual(curLabel);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { ao, label, doDispatchMock } = makeTestRig();
        const prevLabel = "prevLabel";
        const curLabel = "curLabel";
        label.custom = curLabel;
        const action = new SetCustomLabelUndoRedo(prevLabel, curLabel, ao);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=SetCustomLabelUndoRedo.test.js.map