import { makeAppObjectRepo } from "@vived/core";
import { makeBaseAppState } from "../../BaseApp/Entity/BaseAppState";
import { makeToolRepo, ToolState } from "../../Tools/Entities";
import { makeUndoRedoEntity } from "../Entities";
import { UndoRedoToolStatesHook } from "./UndoRedoButtonStatesHook";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const undoRedoEntity = makeUndoRedoEntity(appObjects.getOrCreate("App"));
    const toolRepo = makeToolRepo(appObjects.getOrCreate("ToolRepo"));
    toolRepo.makeTool("UNDO");
    toolRepo.makeTool("REDO");
    const baseApp = makeBaseAppState(appObjects.getOrCreate("App"));
    baseApp.isAuthoring = true;
    new UndoRedoToolStatesHook(appObjects.getOrCreate("AO"));
    return { toolRepo, baseApp, undoRedoEntity };
}
class UndoRedoActionMock {
    constructor() {
        this.undoAction = jest.fn();
        this.redoAction = jest.fn();
        this.type = "mockUndo";
        this.payload = { foo: "bar" };
    }
}
describe("Undo Redo Button State UC Hook", () => {
    it("Initializes the undo redo buttons to disabled", () => {
        const { toolRepo } = makeTestRig();
        const undo = toolRepo.getTool("UNDO");
        expect(undo?.state).toEqual(ToolState.DISABLED);
        const redo = toolRepo.getTool("REDO");
        expect(redo?.state).toEqual(ToolState.DISABLED);
    });
    it("Sets the undo tool enabled once an undo action has been submitted", () => {
        const { toolRepo, undoRedoEntity } = makeTestRig();
        const undo = toolRepo.getTool("UNDO");
        expect(undo?.state).toEqual(ToolState.DISABLED);
        undoRedoEntity.submitAction(new UndoRedoActionMock());
        expect(undo?.state).toEqual(ToolState.ENABLED);
    });
    it("Sets the redo tool enabled once a redo action is available", () => {
        const { toolRepo, undoRedoEntity } = makeTestRig();
        const redo = toolRepo.getTool("REDO");
        undoRedoEntity.submitAction(new UndoRedoActionMock());
        expect(redo?.state).toEqual(ToolState.DISABLED);
        undoRedoEntity.doUndo();
        expect(redo?.state).toEqual(ToolState.ENABLED);
    });
    it("Sets the redo and undo tool hidden when consumption", () => {
        const { toolRepo, baseApp } = makeTestRig();
        baseApp.isAuthoring = false;
        const undo = toolRepo.getTool("UNDO");
        expect(undo?.state).toEqual(ToolState.HIDDEN);
        const redo = toolRepo.getTool("REDO");
        expect(redo?.state).toEqual(ToolState.HIDDEN);
    });
});
//# sourceMappingURL=UndoRedoButtonStatesHook.test.js.map