test(dashboard): add autocomplete trigger/filter tests

This commit is contained in:
teernisse
2026-02-26 16:59:34 -05:00
parent 7059dea3f8
commit 48c3ddce90
3 changed files with 214 additions and 39 deletions

View File

@@ -0,0 +1,48 @@
// Pure logic for autocomplete trigger detection and skill filtering.
// Extracted from SimpleInput.js for testability.
/**
* Detect if cursor is at a trigger position for autocomplete.
* Returns trigger info object or null.
*/
export function getTriggerInfo(value, cursorPos, autocompleteConfig) {
if (!autocompleteConfig) return null;
const { trigger } = autocompleteConfig;
// Find the start of the current "word" (after last whitespace before cursor)
let wordStart = cursorPos;
while (wordStart > 0 && !/\s/.test(value[wordStart - 1])) {
wordStart--;
}
// Check if word starts with this agent's trigger character
if (value[wordStart] === trigger) {
return {
trigger,
filterText: value.slice(wordStart + 1, cursorPos).toLowerCase(),
replaceStart: wordStart,
replaceEnd: cursorPos,
};
}
return null;
}
/**
* Filter and sort skills based on trigger info.
* Returns sorted array of matching skills.
*/
export function filteredSkills(autocompleteConfig, triggerInfo) {
if (!autocompleteConfig || !triggerInfo) return [];
const { skills } = autocompleteConfig;
const { filterText } = triggerInfo;
let filtered = filterText
? skills.filter(s => s.name.toLowerCase().includes(filterText))
: skills.slice();
// Server pre-sorts, but re-sort after filtering for stability
return filtered.sort((a, b) => a.name.localeCompare(b.name));
}