import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { MockUndoRedo } from "../../UndoRedo/Mocks/MockUndoRedo";
import { OverlayColor, OverlayColorEnums } from "../Entities";
import { SetOverlayColorUC } from "./SetOverlayColorUC";
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 overlayColor = new OverlayColor(ao);
    const setOverlayColorUC = new SetOverlayColorUC(ao);
    const mockSubmitWarning = jest.fn();
    appObjects.submitWarning = mockSubmitWarning;
    return {
        appObjects,
        ao,
        mockUndo,
        overlayColor,
        setOverlayColorUC,
        mockDispatcher,
        doDispatchMock,
        mockSubmitWarning,
    };
}
describe("Set Overlay Color UC", () => {
    it("Sets overlay color", () => {
        const { overlayColor, setOverlayColorUC } = makeTestRig();
        overlayColor.overlayColor = OverlayColorEnums.BLACK;
        setOverlayColorUC.setOverlayColor(OverlayColorEnums.WHITE);
        expect(overlayColor.overlayColor).toEqual(OverlayColorEnums.WHITE);
    });
    it("Submits warning if OverlayColor Entity was not added to App Object", () => {
        const { appObjects, mockSubmitWarning } = makeTestRig();
        const ao = appObjects.getOrCreate("testAO");
        new SetOverlayColorUC(ao);
        expect(mockSubmitWarning).toHaveBeenCalled();
    });
    it("Submits warning if label entity was not added to App Object", () => {
        const { appObjects, mockSubmitWarning } = makeTestRig();
        const ao = appObjects.getOrCreate("testAO");
        const setOverlayColorUC = new SetOverlayColorUC(ao);
        setOverlayColorUC.setOverlayColor(OverlayColorEnums.WHITE);
        expect(mockSubmitWarning).toHaveBeenCalledTimes(2);
    });
    it("Dispatches state change when clear custom label", () => {
        const { setOverlayColorUC, doDispatchMock } = makeTestRig();
        setOverlayColorUC.setOverlayColor(OverlayColorEnums.WHITE);
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Submits and undo", () => {
        const { setOverlayColorUC, mockUndo } = makeTestRig();
        setOverlayColorUC.setOverlayColor(OverlayColorEnums.WHITE);
        expect(mockUndo.submitAction).toHaveBeenCalled();
    });
});
//# sourceMappingURL=SetOverlayColorUC.test.js.map