import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { OverlayColor, OverlayColorEnums } from "../../OverlayColor/Entities";
import { SetOverlayColorUndoRedo } from "./SetOverlayColorUndoRedo";
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 overlayColor = new OverlayColor(ao);
    return { mockUndo, mockDispatcher, doDispatchMock, overlayColor, ao };
}
describe("Set Overlay Color Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, ao } = makeTestRig();
        const action = new SetOverlayColorUndoRedo(OverlayColorEnums.BLACK, OverlayColorEnums.WHITE, ao);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo sets the prior overlay color ", () => {
        const { ao, overlayColor } = makeTestRig();
        const prevOverlayColor = OverlayColorEnums.BLACK;
        const curOverlayColor = OverlayColorEnums.WHITE;
        overlayColor.overlayColor = prevOverlayColor;
        const action = new SetOverlayColorUndoRedo(prevOverlayColor, curOverlayColor, ao);
        action.undoAction();
        expect(overlayColor.overlayColor).toEqual(prevOverlayColor);
    });
    it("Redo sets the overlay color back in ", () => {
        const { ao, overlayColor } = makeTestRig();
        const prevOverlayColor = OverlayColorEnums.BLACK;
        const curOverlayColor = OverlayColorEnums.WHITE;
        overlayColor.overlayColor = prevOverlayColor;
        const action = new SetOverlayColorUndoRedo(prevOverlayColor, curOverlayColor, ao);
        action.undoAction();
        action.redoAction();
        expect(overlayColor.overlayColor).toEqual(curOverlayColor);
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { ao, overlayColor, doDispatchMock } = makeTestRig();
        const prevOverlayColor = OverlayColorEnums.BLACK;
        const curOverlayColor = OverlayColorEnums.WHITE;
        overlayColor.overlayColor = prevOverlayColor;
        const action = new SetOverlayColorUndoRedo(prevOverlayColor, curOverlayColor, ao);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=SetOverlayColorUndoRedo.test.js.map