"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 SetCustomLabelUC_1 = require("./SetCustomLabelUC");
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 setCustomLabelUC = new SetCustomLabelUC_1.SetCustomLabelUC(ao);
    const mockSubmitWarning = jest.fn();
    appObjects.submitWarning = mockSubmitWarning;
    return {
        appObjects,
        ao,
        mockUndo,
        mockDispatcher,
        doDispatchMock,
        label,
        setCustomLabelUC,
        mockSubmitWarning,
    };
}
describe("Set Custom Label UC", () => {
    it("Sets custom label", () => {
        const { label, setCustomLabelUC } = makeTestRig();
        label.custom = "";
        setCustomLabelUC.update("custom");
        expect(label.custom).toEqual("custom");
    });
    it("Submits warning if label entity was not added to App Object", () => {
        const { appObjects, mockSubmitWarning } = makeTestRig();
        const ao = appObjects.getOrCreate("testAO");
        const clearCustomLabel = new SetCustomLabelUC_1.SetCustomLabelUC(ao);
        clearCustomLabel.update("custom");
        expect(mockSubmitWarning).toHaveBeenCalledTimes(3);
    });
    it("Dispatches state chagne when clear custom label", () => {
        const { setCustomLabelUC, doDispatchMock } = makeTestRig();
        setCustomLabelUC.update("custom");
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Submits and undo", () => {
        const { setCustomLabelUC, mockUndo } = makeTestRig();
        setCustomLabelUC.update("custom");
        setCustomLabelUC.submit();
        expect(mockUndo.submitAction).toHaveBeenCalled();
    });
    it("Submits undo operation with correct previous and current labels", () => {
        const { label, setCustomLabelUC, mockUndo } = makeTestRig();
        label.custom = "initial";
        setCustomLabelUC.update("custom");
        setCustomLabelUC.submit();
        expect(mockUndo.submitAction).toHaveBeenCalled();
    });
});
//# sourceMappingURL=SetCustomLabelUC.test.js.map