"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 SetOverlayColorUC_1 = require("./SetOverlayColorUC");
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 overlayColor = new Entities_1.OverlayColor(ao);
    const setOverlayColorUC = new SetOverlayColorUC_1.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 = Entities_1.OverlayColorEnums.BLACK;
        setOverlayColorUC.setOverlayColor(Entities_1.OverlayColorEnums.WHITE);
        expect(overlayColor.overlayColor).toEqual(Entities_1.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_1.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_1.SetOverlayColorUC(ao);
        setOverlayColorUC.setOverlayColor(Entities_1.OverlayColorEnums.WHITE);
        expect(mockSubmitWarning).toHaveBeenCalledTimes(2);
    });
    it("Dispatches state change when clear custom label", () => {
        const { setOverlayColorUC, doDispatchMock } = makeTestRig();
        setOverlayColorUC.setOverlayColor(Entities_1.OverlayColorEnums.WHITE);
        expect(doDispatchMock).toHaveBeenCalled();
    });
    it("Submits and undo", () => {
        const { setOverlayColorUC, mockUndo } = makeTestRig();
        setOverlayColorUC.setOverlayColor(Entities_1.OverlayColorEnums.WHITE);
        expect(mockUndo.submitAction).toHaveBeenCalled();
    });
});
//# sourceMappingURL=SetOverlayColorUC.test.js.map