import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange } from "../../Dispatcher";
import { makeUndoRedoEntity } from "../../UndoRedo";
import { Transparency } from "../Entities";
import { makeMakeTransparentUC, MakeTransparentUC } from "./MakeTransparentUC";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const ao = appObjects.getOrCreate("AppObj1");
    const mockDispatchStateChange = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    const undoEntity = makeUndoRedoEntity(appObjects.getOrCreate("undoRedo"));
    const transparencyEntity = new Transparency(ao);
    const uc = makeMakeTransparentUC(ao);
    return {
        appObjects,
        ao,
        transparencyEntity,
        uc,
        doDispatchMock,
        undoEntity,
    };
}
describe("MakeTransparent UC", () => {
    it("Gets the UC", () => {
        const { appObjects, uc } = makeTestRig();
        expect(MakeTransparentUC.get("AppObj1", appObjects)).toEqual(uc);
    });
    it("Toggles the is transparent flag", () => {
        const { uc, transparencyEntity } = makeTestRig();
        transparencyEntity.isTransparent = true;
        uc.toggleIsTransparent();
        expect(transparencyEntity.isTransparent).toEqual(false);
        uc.toggleIsTransparent();
        expect(transparencyEntity.isTransparent).toEqual(true);
    });
    it("Dispatches a state change when toggled", () => {
        const { uc, doDispatchMock } = makeTestRig();
        uc.toggleIsTransparent();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        uc.toggleIsTransparent();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
    it("Submits undo action when toggled", () => {
        const { uc, undoEntity } = makeTestRig();
        undoEntity.submitAction = jest.fn();
        uc.toggleIsTransparent();
        expect(undoEntity.submitAction).toHaveBeenCalled();
    });
    it("Make transparent the object", () => {
        const { uc, transparencyEntity } = makeTestRig();
        transparencyEntity.isTransparent = false;
        uc.makeTransparent();
        expect(transparencyEntity.isTransparent).toEqual(true);
    });
    it("Dispatches a state change when transparent", () => {
        const { uc, doDispatchMock, transparencyEntity } = makeTestRig();
        transparencyEntity.isTransparent = false;
        uc.makeTransparent();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
    });
    it("Submits undo action when transparent", () => {
        const { uc, undoEntity } = makeTestRig();
        undoEntity.submitAction = jest.fn();
        uc.makeTransparent();
        expect(undoEntity.submitAction).toHaveBeenCalled();
    });
    it("Does not dispatch a state change if already transparent", () => {
        const { uc, doDispatchMock, transparencyEntity } = makeTestRig();
        transparencyEntity.isTransparent = true;
        uc.makeTransparent();
        expect(doDispatchMock).toHaveBeenCalledTimes(0);
    });
    it("Does not submit undo action when already transparent", () => {
        const { uc, undoEntity, transparencyEntity } = makeTestRig();
        undoEntity.submitAction = jest.fn();
        transparencyEntity.isTransparent = true;
        uc.makeTransparent();
        expect(undoEntity.submitAction).not.toHaveBeenCalled();
    });
    it("Sets up the Undo Redo for transparent", () => {
        const { uc, undoEntity, transparencyEntity } = makeTestRig();
        transparencyEntity.isTransparent = false;
        uc.makeTransparent();
        expect(transparencyEntity.isTransparent).toEqual(true);
        undoEntity.doUndo();
        expect(transparencyEntity.isTransparent).toEqual(false);
        undoEntity.doRedo();
        expect(transparencyEntity.isTransparent).toEqual(true);
    });
    it("Sets up the Undo Redo for an unmake transparent", () => {
        const { uc, undoEntity, transparencyEntity } = makeTestRig();
        transparencyEntity.isTransparent = true;
        uc.toggleIsTransparent();
        expect(transparencyEntity.isTransparent).toEqual(false);
        undoEntity.doUndo();
        expect(transparencyEntity.isTransparent).toEqual(true);
        undoEntity.doRedo();
        expect(transparencyEntity.isTransparent).toEqual(false);
    });
});
//# sourceMappingURL=MakeTransparentUC.test.js.map