"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const InputQueueManager_1 = require("../../src/utils/InputQueueManager");
describe("InputQueueManager history ordering", () => {
    test("should use only passed-in history for navigation", () => {
        const manager = new InputQueueManager_1.InputQueueManager();
        const history = ["old1", "old2", "old3"];
        const getHistory = manager.getHistory.bind(manager);
        manager.stack = [{
                question: "test",
                options: [],
                history: history,
                resolve: () => { }
            }];
        const result = getHistory();
        expect(result).toEqual(["old1", "old2", "old3"]);
    });
    test("should sanitize history entries", () => {
        const manager = new InputQueueManager_1.InputQueueManager();
        const history = ["normal", "has\nnewline", "  spaces  ", ""];
        const getHistory = manager.getHistory.bind(manager);
        manager.stack = [{
                question: "test",
                options: [],
                history: history,
                resolve: () => { }
            }];
        const result = getHistory();
        expect(result).toEqual(["normal", "has newline", "spaces"]);
    });
    test("should return empty array when no history provided", () => {
        const manager = new InputQueueManager_1.InputQueueManager();
        const getHistory = manager.getHistory.bind(manager);
        manager.stack = [{
                question: "test",
                options: [],
                history: undefined,
                resolve: () => { }
            }];
        const result = getHistory();
        expect(result).toEqual([]);
    });
    test("should return empty array when stack is empty", () => {
        const manager = new InputQueueManager_1.InputQueueManager();
        const getHistory = manager.getHistory.bind(manager);
        manager.stack = [];
        const result = getHistory();
        expect(result).toEqual([]);
    });
    test("Verify historyIndex math for first Up press", () => {
        const history = ["old1", "old2", "recent"];
        const historyIndex = 0;
        const accessIndex = history.length - 1 - historyIndex;
        expect(accessIndex).toBe(2);
        expect(history[accessIndex]).toBe("recent");
    });
    test("Verify historyIndex math for multiple Up presses", () => {
        const history = ["old1", "old2", "recent"];
        expect(history[history.length - 1 - 0]).toBe("recent");
        expect(history[history.length - 1 - 1]).toBe("old2");
        expect(history[history.length - 1 - 2]).toBe("old1");
    });
    test("onNewEntry callback is called when set", () => {
        const manager = new InputQueueManager_1.InputQueueManager();
        const entries = [];
        manager.setOnNewEntry((entry) => {
            entries.push(entry);
        });
        expect(manager.onNewEntry).toBeDefined();
    });
});
describe("InputQueueManager with CliChatService integration pattern", () => {
    test("new entries should appear in history for next ask() call", () => {
        const inputHistory = ["old1", "old2"];
        const manager = new InputQueueManager_1.InputQueueManager();
        manager.setOnNewEntry((entry) => {
            if (!entry.startsWith("/") && entry.trim() !== "") {
                inputHistory.push(entry);
            }
        });
        const getHistory = manager.getHistory.bind(manager);
        manager.stack = [{
                question: "test",
                options: [],
                history: [...inputHistory],
                resolve: () => { }
            }];
        let result = getHistory();
        expect(result).toEqual(["old1", "old2"]);
        manager.onNewEntry("new message");
        expect(inputHistory).toEqual(["old1", "old2", "new message"]);
        manager.stack = [{
                question: "test2",
                options: [],
                history: [...inputHistory],
                resolve: () => { }
            }];
        result = getHistory();
        expect(result).toEqual(["old1", "old2", "new message"]);
        const historyIndex = 0;
        expect(result[result.length - 1 - historyIndex]).toBe("new message");
    });
});
//# sourceMappingURL=InputQueueManager.test.js.map