Skip to content

Commit eb0f114

Browse files
test(ModelPicker): add keyboard handling to mock Select component
Cause: The issue was that the mock `Select` component in the test didn't implement keyboard handling. When the test sent keys via `stdin.write()`, they weren't being processed because the mock was just rendering static text without `useInput`. Fix: Added `useInput` to the mock `Select` component to handle the Enter key, which allows keyboard events to flow through the component hierarchy properly.
1 parent 40c0338 commit eb0f114

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/components/ModelPicker.test.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { mockListModels, mockOnChange } = vi.hoisted(() => ({
99
}));
1010

1111
vi.mock('@inkjs/ui', async () => {
12-
const { Text } = await import('ink');
12+
const { Text, useInput } = await import('ink');
1313
return {
1414
Spinner: ({ label }: { label?: string }) => (
1515
<Text>{`⏳${label ?? ''}`}</Text>
@@ -23,6 +23,13 @@ vi.mock('@inkjs/ui', async () => {
2323
onChange?: (value: string) => void;
2424
}) => {
2525
mockOnChange.mockImplementation((v) => onChange?.(v));
26+
27+
useInput((_input, key) => {
28+
if (key.return && options.length > 0) {
29+
onChange?.(options[0].value);
30+
}
31+
});
32+
2633
return (
2734
<>
2835
{options.map(({ value, label }) => (

0 commit comments

Comments
 (0)