import { makeAppObjectRepo } from "@vived/core";
import { makeUndoRedoEntity } from "../Entities/UndoRedoEntity";
import { HasUndoPM, makeHasUndoPM } from "./HasUndoPM";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const app = appObjects.getOrCreate("app");
    const undoRedoEntity = makeUndoRedoEntity(app);
    const pm = makeHasUndoPM(app);
    const mockHasUndo = jest.spyOn(undoRedoEntity, "hasUndo", "get");
    mockHasUndo.mockReturnValue(true);
    return { undoRedoEntity, pm, appObjects, mockHasUndo };
}
describe("Has Redo Presentation Manager", () => {
    it("Updates the view when the the flag changes", () => {
        const { mockHasUndo, pm, undoRedoEntity } = makeTestRig();
        const view = jest.fn();
        pm.addView(view);
        mockHasUndo.mockReturnValue(false);
        undoRedoEntity.notifyOnChange();
        expect(view).toHaveBeenCalledWith(false);
        mockHasUndo.mockReturnValue(true);
        undoRedoEntity.notifyOnChange();
        expect(view).toHaveBeenCalledWith(true);
    });
    it("Checks for VMs to be equal", () => {
        const { pm } = makeTestRig();
        expect(pm.vmsAreEqual(false, true)).toEqual(false);
        expect(pm.vmsAreEqual(true, false)).toEqual(false);
        expect(pm.vmsAreEqual(true, true)).toEqual(true);
        expect(pm.vmsAreEqual(false, false)).toEqual(true);
    });
    it("Warns if it is added to something that does not have a App State Entity", () => {
        const { appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        const ao = appObjects.getOrCreate("anotherOne");
        makeHasUndoPM(ao);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Gets the PM", () => {
        const { pm, appObjects } = makeTestRig();
        expect(HasUndoPM.get(appObjects)).toEqual(pm);
    });
});
//# sourceMappingURL=HasUndoPM.test.js.map