"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 ClearCustomLabelUC_1 = require("./ClearCustomLabelUC");
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);
    const clearCustomLabelUC = new ClearCustomLabelUC_1.ClearCustomLabelUC(ao);
    const mockSubmitWarning = jest.fn();
    appObjects.submitWarning = mockSubmitWarning;
    return {
        appObjects,
        ao,
        mockUndo,
        mockDispatcher,
        doDispatchMock,
        label,
        clearCustomLabelUC,
        mockSubmitWarning,
    };
}
describe("Clear Custom Label UC", () => {
    it("Clears custom label", () => {
        const { label, clearCustomLabelUC } = makeTestRig();
        label.custom = "custom";
        clearCustomLabelUC.clearCustomLabel();
        expect(label.custom).toEqual("");
    });
    it("Submits warning if label entity was not added to App Object", () => {
        const { appObjects, mockSubmitWarning } = makeTestRig();
        const ao = appObjects.getOrCreate("testAO");
        const clearCustomLabel = new ClearCustomLabelUC_1.ClearCustomLabelUC(ao);
        clearCustomLabel.clearCustomLabel();
        expect(mockSubmitWarning).toHaveBeenCalledTimes(2);
    });
    it("Dispatches state chagne when clear custom label", () => {
        const { label, clearCustomLabelUC, doDispatchMock } = makeTestRig();
        label.custom = "custom";
        clearCustomLabelUC.clearCustomLabel();
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Submits and undo", () => {
        const { label, clearCustomLabelUC, mockUndo } = makeTestRig();
        label.custom = "custom";
        clearCustomLabelUC.clearCustomLabel();
        expect(mockUndo.submitAction).toHaveBeenCalled();
    });
});
//# sourceMappingURL=ClearCustomLabelUC.test.js.map