"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const UndoRedo_1 = require("../../UndoRedo");
const Entities_1 = require("../Entities");
const MakeTransparentUC_1 = require("./MakeTransparentUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("AppObj1");
    const mockDispatchStateChange = (0, Dispatcher_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    const undoEntity = (0, UndoRedo_1.makeUndoRedoEntity)(appObjects.getOrCreate("undoRedo"));
    const transparencyEntity = new Entities_1.Transparency(ao);
    const uc = (0, MakeTransparentUC_1.makeMakeTransparentUC)(ao);
    return {
        appObjects,
        ao,
        transparencyEntity,
        uc,
        doDispatchMock,
        undoEntity,
    };
}
describe("MakeTransparent UC", () => {
    it("Gets the UC", () => {
        const { appObjects, uc } = makeTestRig();
        expect(MakeTransparentUC_1.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