"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const MockDispatchStateChange_1 = require("../../Dispatcher/Mocks/MockDispatchStateChange");
const MockUndoRedo_1 = require("../../UndoRedo/Mocks/MockUndoRedo");
const Entities_1 = require("../Entities");
const SetCustomLabelUndoRedo_1 = require("./SetCustomLabelUndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("App");
    const mockUndo = new MockUndoRedo_1.MockUndoRedo(ao);
    const mockDispatcher = new MockDispatchStateChange_1.MockDispatchStateChange(ao);
    const label = (0, Entities_1.makeLabelEntity)(ao);
    return { mockUndo, mockDispatcher, label, ao };
}
describe("Set Custom Label Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, ao } = makeTestRig();
        const action = new SetCustomLabelUndoRedo_1.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_1.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_1.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, mockDispatcher } = makeTestRig();
        const prevLabel = "prevLabel";
        const curLabel = "curLabel";
        label.custom = curLabel;
        const action = new SetCustomLabelUndoRedo_1.SetCustomLabelUndoRedo(prevLabel, curLabel, ao);
        action.undoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(mockDispatcher.doDispatch).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=SetCustomLabelUndoRedo.test.js.map