Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/components/Chat/Input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ vi.mock('@inkjs/ui', () => ({
isDisabled,
onChange,
onSubmit,
placeholder,
}: {
defaultValue?: string;
isDisabled?: boolean;
onChange?: (value: string) => void;
onSubmit?: (value: string) => void;
placeholder?: string;
}) => {
const [value, setValue] = useState(defaultValue ?? '');
const valueRef = useRef(defaultValue ?? '');
Expand Down Expand Up @@ -56,7 +58,16 @@ vi.mock('@inkjs/ui', () => ({
setValue(nextValue);
});

return <Text>{value}</Text>;
return (
<>
<Text>{value === '' ? (placeholder ?? '') : value}</Text>
{value ? (
<Text dimColor>{`[value:${value}]`}</Text>
) : (
<Text dimColor>{`[placeholder:${placeholder ?? ''}]`}</Text>
)}
</>
);
},
}));

Expand Down Expand Up @@ -169,6 +180,10 @@ describe('Input', () => {
it('renders input prompt', () => {
const { lastFrame } = render(<Input onSubmit={vi.fn()} />);
expect(lastFrame()).toContain('>');
expect(lastFrame()).toContain('Ask anything... (/ commands, @ files)');
expect(lastFrame()).toContain(
'[placeholder:Ask anything... (/ commands, @ files)]',
);
});

it('does not show command suggestion on non-slash input', async () => {
Expand Down Expand Up @@ -337,9 +352,13 @@ describe('Input', () => {
await test.tick();
stdin.write('i');
await test.tick();
expect(lastFrame()).toContain('[value:hi]');
stdin.write(KEY.ENTER);
await test.tick(10);
expect(lastFrame()).not.toContain('hi');
expect(lastFrame()).not.toContain('[value:hi]');
expect(lastFrame()).toContain(
'[placeholder:Ask anything... (/ commands, @ files)]',
);
});

it('deletes last character on backspace', async () => {
Expand Down Expand Up @@ -375,7 +394,10 @@ describe('Input', () => {
);
stdin.write('h');
await test.tick();
expect(lastFrame()).not.toContain('h');
expect(lastFrame()).not.toContain('[value:h]');
expect(lastFrame()).toContain(
'[placeholder:Ask anything... (/ commands, @ files)]',
);
stdin.write(KEY.ENTER);
await test.tick();
expect(onSubmit).not.toHaveBeenCalled();
Expand Down
1 change: 1 addition & 0 deletions src/components/Chat/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export function Input({ isDisabled = false, onSubmit }: Props) {
key={resetKey}
onChange={setInput}
onSubmit={handleSubmitText}
placeholder="Ask anything... (/ commands, @ files)"
/>
</Box>

Expand Down
Loading