({
atSuggestions = [],
slashSuggestions = [],
isLoading = false,
isPerfectMatch = false,
slashCompletionRange = { completionStart: 0, completionEnd: 0 },
}: {
atSuggestions?: Suggestion[];
slashSuggestions?: Suggestion[];
isLoading?: boolean;
isPerfectMatch?: boolean;
slashCompletionRange?: { completionStart: number; completionEnd: number };
})
| 34 | |
| 35 | // Helper to set up mocks in a consistent way for both child hooks |
| 36 | const setupMocks = ({ |
| 37 | atSuggestions = [], |
| 38 | slashSuggestions = [], |
| 39 | isLoading = false, |
| 40 | isPerfectMatch = false, |
| 41 | slashCompletionRange = { completionStart: 0, completionEnd: 0 }, |
| 42 | }: { |
| 43 | atSuggestions?: Suggestion[]; |
| 44 | slashSuggestions?: Suggestion[]; |
| 45 | isLoading?: boolean; |
| 46 | isPerfectMatch?: boolean; |
| 47 | slashCompletionRange?: { completionStart: number; completionEnd: number }; |
| 48 | }) => { |
| 49 | // Mock for @-completions |
| 50 | (useAtCompletion as vi.Mock).mockImplementation( |
| 51 | ({ |
| 52 | enabled, |
| 53 | setSuggestions, |
| 54 | setIsLoadingSuggestions, |
| 55 | }: UseAtCompletionProps) => { |
| 56 | useEffect(() => { |
| 57 | if (enabled) { |
| 58 | setIsLoadingSuggestions(isLoading); |
| 59 | setSuggestions(atSuggestions); |
| 60 | } |
| 61 | }, [enabled, setSuggestions, setIsLoadingSuggestions]); |
| 62 | }, |
| 63 | ); |
| 64 | |
| 65 | // Mock for /-completions |
| 66 | (useSlashCompletion as vi.Mock).mockImplementation( |
| 67 | ({ |
| 68 | enabled, |
| 69 | setSuggestions, |
| 70 | setIsLoadingSuggestions, |
| 71 | setIsPerfectMatch, |
| 72 | }: UseSlashCompletionProps) => { |
| 73 | useEffect(() => { |
| 74 | if (enabled) { |
| 75 | setIsLoadingSuggestions(isLoading); |
| 76 | setSuggestions(slashSuggestions); |
| 77 | setIsPerfectMatch(isPerfectMatch); |
| 78 | } |
| 79 | }, [enabled, setSuggestions, setIsLoadingSuggestions, setIsPerfectMatch]); |
| 80 | // The hook returns a range, which we can mock simply |
| 81 | return slashCompletionRange; |
| 82 | }, |
| 83 | ); |
| 84 | }; |
| 85 | |
| 86 | describe('useCommandCompletion', () => { |
| 87 | const mockCommandContext = {} as CommandContext; |
no outgoing calls
no test coverage detected