"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("../Entities");
const ClearCustomLabelUndoRedo_1 = require("./ClearCustomLabelUndoRedo");
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 label = (0, Entities_1.makeLabelEntity)(ao);
    return { mockUndo, mockDispatcher, doDispatchMock, label, ao };
}
describe("Clear Custom Label Undo Redo action", () => {
    it("Submits itself to the entity", () => {
        const { mockUndo, ao } = makeTestRig();
        const action = new ClearCustomLabelUndoRedo_1.ClearCustomLabelUndoRedo("custom", ao);
        expect(mockUndo.submitAction).toHaveBeenCalledWith(action);
    });
    it("Undo sets the prior custom label ", () => {
        const { ao, label } = makeTestRig();
        const customLabel = "custom";
        label.custom = customLabel;
        const action = new ClearCustomLabelUndoRedo_1.ClearCustomLabelUndoRedo(customLabel, ao);
        action.undoAction();
        expect(label.custom).toEqual(customLabel);
    });
    it("Redo clears the custome label", () => {
        const { ao, label } = makeTestRig();
        const customLabel = "custom";
        label.custom = customLabel;
        const action = new ClearCustomLabelUndoRedo_1.ClearCustomLabelUndoRedo(customLabel, ao);
        action.undoAction();
        action.redoAction();
        expect(label.custom).toEqual("");
    });
    it("Dispatches state changes for both the undo and redo action", () => {
        const { ao, label, doDispatchMock } = makeTestRig();
        const customLabel = "custom";
        label.custom = customLabel;
        const action = new ClearCustomLabelUndoRedo_1.ClearCustomLabelUndoRedo("", ao);
        action.undoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        action.redoAction();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
});
//# sourceMappingURL=ClearCustomLabelUndoRedo.test.js.map