import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { makeLabelEntity } from "../Entities";
import { ClearCustomLabelUC } from "./ClearCustomLabelUC";
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 clearCustomLabelUC = new 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(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