mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-10 21:30:40 -07:00
Enable 'Other' option for yesno question type (#24545)
This commit is contained in:
@@ -1409,6 +1409,53 @@ describe('AskUserDialog', () => {
|
||||
expect(lastFrame()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('supports "Other" option for yesno questions', async () => {
|
||||
const questions: Question[] = [
|
||||
{
|
||||
question: 'Is this correct?',
|
||||
header: 'Confirm',
|
||||
type: QuestionType.YESNO,
|
||||
},
|
||||
];
|
||||
|
||||
const onSubmit = vi.fn();
|
||||
const { stdin, lastFrame, waitUntilReady } = await renderWithProviders(
|
||||
<AskUserDialog
|
||||
questions={questions}
|
||||
onSubmit={onSubmit}
|
||||
onCancel={vi.fn()}
|
||||
width={80}
|
||||
/>,
|
||||
{ width: 80 },
|
||||
);
|
||||
|
||||
// Navigate to "Other" (3rd option: 1. Yes, 2. No, 3. Other)
|
||||
writeKey(stdin, '\x1b[B'); // Down to No
|
||||
writeKey(stdin, '\x1b[B'); // Down to Other
|
||||
|
||||
await waitFor(async () => {
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('Enter a custom value');
|
||||
});
|
||||
|
||||
// Type feedback
|
||||
for (const char of 'Yes, but with caveats') {
|
||||
writeKey(stdin, char);
|
||||
}
|
||||
|
||||
await waitFor(async () => {
|
||||
await waitUntilReady();
|
||||
expect(lastFrame()).toContain('Yes, but with caveats');
|
||||
});
|
||||
|
||||
// Submit
|
||||
writeKey(stdin, '\r');
|
||||
|
||||
await waitFor(async () => {
|
||||
expect(onSubmit).toHaveBeenCalledWith({ '0': 'Yes, but with caveats' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('expands paste placeholders in multi-select custom option via Done', async () => {
|
||||
|
||||
@@ -511,8 +511,9 @@ const ChoiceQuestionView: React.FC<ChoiceQuestionViewProps> = ({
|
||||
}) => {
|
||||
const keyMatchers = useKeyMatchers();
|
||||
const isAlternateBuffer = useAlternateBuffer();
|
||||
const numOptions =
|
||||
(question.options?.length ?? 0) + (question.type !== 'yesno' ? 1 : 0);
|
||||
const hasAll = question.multiSelect && (question.options?.length ?? 0) > 1;
|
||||
// Calculate total options including 'All' and 'Other' to ensure consistent numbering column width
|
||||
const numOptions = (question.options?.length ?? 0) + (hasAll ? 1 : 0) + 1;
|
||||
const numLen = String(numOptions).length;
|
||||
const radioWidth = 2; // "● "
|
||||
const numberWidth = numLen + 2; // e.g., "1. "
|
||||
@@ -735,17 +736,15 @@ const ChoiceQuestionView: React.FC<ChoiceQuestionViewProps> = ({
|
||||
list.push({ key: 'all', value: allItem });
|
||||
}
|
||||
|
||||
// Only add custom option for choice type, not yesno
|
||||
if (question.type !== 'yesno') {
|
||||
const otherItem: OptionItem = {
|
||||
key: 'other',
|
||||
label: customOptionText || '',
|
||||
description: '',
|
||||
type: 'other',
|
||||
index: list.length,
|
||||
};
|
||||
list.push({ key: 'other', value: otherItem });
|
||||
}
|
||||
// Add custom option for choice and yesno types
|
||||
const otherItem: OptionItem = {
|
||||
key: 'other',
|
||||
label: customOptionText || '',
|
||||
description: '',
|
||||
type: 'other',
|
||||
index: list.length,
|
||||
};
|
||||
list.push({ key: 'other', value: otherItem });
|
||||
|
||||
if (question.multiSelect) {
|
||||
const doneItem: OptionItem = {
|
||||
@@ -759,7 +758,7 @@ const ChoiceQuestionView: React.FC<ChoiceQuestionViewProps> = ({
|
||||
}
|
||||
|
||||
return list;
|
||||
}, [questionOptions, question.multiSelect, question.type, customOptionText]);
|
||||
}, [questionOptions, question.multiSelect, customOptionText]);
|
||||
|
||||
const handleHighlight = useCallback(
|
||||
(itemValue: OptionItem) => {
|
||||
|
||||
Reference in New Issue
Block a user