"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const BaseAppState_1 = require("../../BaseApp/Entity/BaseAppState");
const Entities_1 = require("../../Tools/Entities");
const Entities_2 = require("../Entities");
const UndoRedoButtonStatesHook_1 = require("./UndoRedoButtonStatesHook");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const undoRedoEntity = (0, Entities_2.makeUndoRedoEntity)(appObjects.getOrCreate("App"));
    const toolRepo = (0, Entities_1.makeToolRepo)(appObjects.getOrCreate("ToolRepo"));
    toolRepo.makeTool("UNDO");
    toolRepo.makeTool("REDO");
    const baseApp = (0, BaseAppState_1.makeBaseAppState)(appObjects.getOrCreate("App"));
    baseApp.isAuthoring = true;
    new UndoRedoButtonStatesHook_1.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(Entities_1.ToolState.DISABLED);
        const redo = toolRepo.getTool("REDO");
        expect(redo?.state).toEqual(Entities_1.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(Entities_1.ToolState.DISABLED);
        undoRedoEntity.submitAction(new UndoRedoActionMock());
        expect(undo?.state).toEqual(Entities_1.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(Entities_1.ToolState.DISABLED);
        undoRedoEntity.doUndo();
        expect(redo?.state).toEqual(Entities_1.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(Entities_1.ToolState.HIDDEN);
        const redo = toolRepo.getTool("REDO");
        expect(redo?.state).toEqual(Entities_1.ToolState.HIDDEN);
    });
});
//# sourceMappingURL=UndoRedoButtonStatesHook.test.js.map