"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const Entities_1 = require("../../OverlayColor/Entities");
const SetOverlayColorUndoRedo_1 = require("./SetOverlayColorUndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("App");
    const mockUndo = new MockUndoRedo_1.MockUndoRedo(ao);
    // Override the submitAction with a jest.fn()
    mockUndo.submitAction = jest.fn();
    const mockDispatcher = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const overlayColor = new Entities_1.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_1.SetOverlayColorUndoRedo(Entities_1.OverlayColorEnums.BLACK, Entities_1.OverlayColorEnums.WHITE, ao);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo sets the prior overlay color ", () => {
        const { ao, overlayColor } = makeTestRig();
        const prevOverlayColor = Entities_1.OverlayColorEnums.BLACK;
        const curOverlayColor = Entities_1.OverlayColorEnums.WHITE;
        overlayColor.overlayColor = prevOverlayColor;
        const action = new SetOverlayColorUndoRedo_1.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 = Entities_1.OverlayColorEnums.BLACK;
        const curOverlayColor = Entities_1.OverlayColorEnums.WHITE;
        overlayColor.overlayColor = prevOverlayColor;
        const action = new SetOverlayColorUndoRedo_1.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 = Entities_1.OverlayColorEnums.BLACK;
        const curOverlayColor = Entities_1.OverlayColorEnums.WHITE;
        overlayColor.overlayColor = prevOverlayColor;
        const action = new SetOverlayColorUndoRedo_1.SetOverlayColorUndoRedo(prevOverlayColor, curOverlayColor, ao);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=SetOverlayColorUndoRedo.test.js.map