import { describe, expect, it } from "vitest"; import { stripAnsi, visibleWidth } from "../../terminal/ansi.js"; import { SearchableSelectList, type SearchableSelectListTheme } from "./searchable-select-list.js";
function expectDescriptionVisibilityAtWidth(width: number, shouldContainDescription: boolean) { const items = [
{ value: "one", label: "one", description: "desc" },
{ value: "two", label: "two", description: "desc" },
]; const list = new SearchableSelectList(items, 5, mockTheme); // Ensure first row is non-selected so description styling path is exercised.
list.setSelectedIndex(1); const output = list.render(width).join("\n"); if (shouldContainDescription) {
expect(output).toContain("(desc)");
} else {
expect(output).not.toContain("(desc)");
}
}
it("renders all items when no filter is applied", () => { const list = new SearchableSelectList(testItems, 5, mockTheme); const output = list.render(80);
// Should have search prompt line, spacer, and items
expect(output.length).toBeGreaterThanOrEqual(3);
expect(output[0]).toContain("search");
});
it("does not truncate long labels on wide terminals when description is present", () => { const tail = "__TAIL__"; const longLabel = `session-${"x".repeat(40)}${tail}`; // > 30 chars; tail would be lost before PR const items = [{ value: longLabel, label: longLabel, description: "desc" }]; const list = new SearchableSelectList(items, 5, mockTheme);
it("prioritizes exact substring matches over fuzzy matches", () => { // Add items where one has early exact match, others are fuzzy or late matches const items = [
{ value: "openrouter/auto", label: "openrouter/auto", description: "Routes to best" },
{ value: "opus-direct", label: "opus-direct", description: "Direct opus model" },
{
value: "anthropic/claude-3-opus",
label: "anthropic/claude-3-opus",
description: "Claude 3 Opus",
},
]; const list = new SearchableSelectList(items, 5, mockTheme);
// Type "opus" - should match "opus-direct" first (earliest exact substring)
typeInput(list, "opus");
// First result should be "opus-direct" where "opus" appears at position 0 const selected = list.getSelectedItem();
expect(selected?.value).toBe("opus-direct");
});
it("calls onSelect when enter is pressed", () => { const list = new SearchableSelectList(testItems, 5, mockTheme);
let selectedValue: string | undefined;
it("calls onCancel when escape is pressed", () => { const list = new SearchableSelectList(testItems, 5, mockTheme);
let cancelled = false;
list.onCancel = () => {
cancelled = true;
};
// Press escape
list.handleInput("\x1b");
expect(cancelled).toBe(true);
});
});
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.11Bemerkung:
(vorverarbeitet am 2026-06-10)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.