"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Entities_1 = require("../Entities");
const HideUC_1 = require("./HideUC");
const MockDispatchStateChange_1 = require("../../Dispatcher/Mocks/MockDispatchStateChange");
const UndoRedo_1 = require("../../UndoRedo");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("AppObj1");
    const mockDispatchStateChange = (0, MockDispatchStateChange_1.makeMockDispatchStateChange)(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    const undoEntity = (0, UndoRedo_1.makeUndoRedoEntity)(appObjects.getOrCreate("undoRedo"));
    const hideableEntity = new Entities_1.Hideable(ao);
    const uc = (0, HideUC_1.makeHideUC)(ao);
    return {
        appObjects,
        ao,
        hideableEntity,
        uc,
        doDispatchMock,
        undoEntity,
    };
}
describe("Hide UC", () => {
    it("Gets the UC", () => {
        const { appObjects, uc } = makeTestRig();
        expect(HideUC_1.HideUC.get("AppObj1", appObjects)).toEqual(uc);
    });
    it("Toggles the is hidden flag", () => {
        const { uc, hideableEntity } = makeTestRig();
        hideableEntity.isHidden = true;
        uc.toggleIsHidden();
        expect(hideableEntity.isHidden).toEqual(false);
        uc.toggleIsHidden();
        expect(hideableEntity.isHidden).toEqual(true);
    });
    it("Dispatches a state change when toggled", () => {
        const { uc, doDispatchMock } = makeTestRig();
        uc.toggleIsHidden();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
        uc.toggleIsHidden();
        expect(doDispatchMock).toHaveBeenCalledTimes(2);
    });
    it("Submits undo action when toggled", () => {
        const { uc, undoEntity } = makeTestRig();
        undoEntity.submitAction = jest.fn();
        uc.toggleIsHidden();
        expect(undoEntity.submitAction).toHaveBeenCalled();
    });
    it("Hides the object", () => {
        const { uc, hideableEntity } = makeTestRig();
        hideableEntity.isHidden = false;
        uc.hide();
        expect(hideableEntity.isHidden).toEqual(true);
    });
    it("Dispatches a state change when hidden", () => {
        const { uc, doDispatchMock, hideableEntity } = makeTestRig();
        hideableEntity.isHidden = false;
        uc.hide();
        expect(doDispatchMock).toHaveBeenCalledTimes(1);
    });
    it("Submits undo action when hidden", () => {
        const { uc, undoEntity } = makeTestRig();
        undoEntity.submitAction = jest.fn();
        uc.hide();
        expect(undoEntity.submitAction).toHaveBeenCalled();
    });
    it("Does not dispatch a state change if already hidden hidden", () => {
        const { uc, doDispatchMock, hideableEntity } = makeTestRig();
        hideableEntity.isHidden = true;
        uc.hide();
        expect(doDispatchMock).toHaveBeenCalledTimes(0);
    });
    it("Does not submit undo action when already hidden", () => {
        const { uc, undoEntity, hideableEntity } = makeTestRig();
        undoEntity.submitAction = jest.fn();
        hideableEntity.isHidden = true;
        uc.hide();
        expect(undoEntity.submitAction).not.toHaveBeenCalled();
    });
    it("Sets up the Undo Redo for a hide", () => {
        const { uc, undoEntity, hideableEntity } = makeTestRig();
        hideableEntity.isHidden = false;
        uc.hide();
        expect(hideableEntity.isHidden).toEqual(true);
        undoEntity.doUndo();
        expect(hideableEntity.isHidden).toEqual(false);
        undoEntity.doRedo();
        expect(hideableEntity.isHidden).toEqual(true);
    });
    it("Sets up the Undo Redo for an unhide", () => {
        const { uc, undoEntity, hideableEntity } = makeTestRig();
        hideableEntity.isHidden = true;
        uc.toggleIsHidden();
        expect(hideableEntity.isHidden).toEqual(false);
        undoEntity.doUndo();
        expect(hideableEntity.isHidden).toEqual(true);
        undoEntity.doRedo();
        expect(hideableEntity.isHidden).toEqual(false);
    });
});
//# sourceMappingURL=HideUC.test.js.map