import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeLabelEntity } from "../Entities";
import { SetCustomLabelUC } from "./SetCustomLabelUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("App");
    const mockUndo = new MockUndoRedo(ao);
    // Override the submitAction with a jest.fn()
    mockUndo.submitAction = jest.fn();
    const mockDispatcher = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatcher.doDispatch = doDispatchMock;
    const label = makeLabelEntity(ao);
    const setCustomLabelUC = new 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(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