diff --git a/packages/prompts/src/__snapshots__/index.test.ts.snap b/packages/prompts/src/__snapshots__/index.test.ts.snap index 53b3d447..34f90057 100644 --- a/packages/prompts/src/__snapshots__/index.test.ts.snap +++ b/packages/prompts/src/__snapshots__/index.test.ts.snap @@ -169,6 +169,31 @@ exports[`prompts (isCI = false) > multiselect > can cancel 1`] = ` ] `; +exports[`prompts (isCI = false) > multiselect > can render option hints 1`] = ` +[ + "[?25l", + "│ +◆ foo +│ ◻ opt0 (Hint 0) +│ ◻ opt1 +└ +", + "", + "", + "", + "│ ◼ opt0 (Hint 0)", + "", + "", + "", + "", + "◇ foo +│ opt0", + " +", + "[?25h", +] +`; + exports[`prompts (isCI = false) > multiselect > can set cursorAt to preselect an option 1`] = ` [ "[?25l", @@ -194,6 +219,31 @@ exports[`prompts (isCI = false) > multiselect > can set cursorAt to preselect an ] `; +exports[`prompts (isCI = false) > multiselect > can set custom labels 1`] = ` +[ + "[?25l", + "│ +◆ foo +│ ◻ Option 0 +│ ◻ Option 1 +└ +", + "", + "", + "", + "│ ◼ Option 0", + "", + "", + "", + "", + "◇ foo +│ Option 0", + " +", + "[?25h", +] +`; + exports[`prompts (isCI = false) > multiselect > can set initial values 1`] = ` [ "[?25l", @@ -349,6 +399,46 @@ exports[`prompts (isCI = false) > multiselect > renders message 1`] = ` ] `; +exports[`prompts (isCI = false) > multiselect > renders multiple cancelled values 1`] = ` +[ + "[?25l", + "│ +◆ foo +│ ◻ opt0 +│ ◻ opt1 +│ ◻ opt2 +└ +", + "", + "", + "", + "│ ◼ opt0", + "", + "", + "", + "", + "│ ◼ opt0 +│ ◻ opt1 +│ ◻ opt2 +└ +", + "", + "", + "", + "│ ◼ opt1", + "", + "", + "", + "", + "■ foo +│ opt0, opt1 +│", + " +", + "[?25h", +] +`; + exports[`prompts (isCI = false) > multiselect > renders multiple selected options 1`] = ` [ "[?25l", @@ -1244,6 +1334,31 @@ exports[`prompts (isCI = true) > multiselect > can cancel 1`] = ` ] `; +exports[`prompts (isCI = true) > multiselect > can render option hints 1`] = ` +[ + "[?25l", + "│ +◆ foo +│ ◻ opt0 (Hint 0) +│ ◻ opt1 +└ +", + "", + "", + "", + "│ ◼ opt0 (Hint 0)", + "", + "", + "", + "", + "◇ foo +│ opt0", + " +", + "[?25h", +] +`; + exports[`prompts (isCI = true) > multiselect > can set cursorAt to preselect an option 1`] = ` [ "[?25l", @@ -1269,6 +1384,31 @@ exports[`prompts (isCI = true) > multiselect > can set cursorAt to preselect an ] `; +exports[`prompts (isCI = true) > multiselect > can set custom labels 1`] = ` +[ + "[?25l", + "│ +◆ foo +│ ◻ Option 0 +│ ◻ Option 1 +└ +", + "", + "", + "", + "│ ◼ Option 0", + "", + "", + "", + "", + "◇ foo +│ Option 0", + " +", + "[?25h", +] +`; + exports[`prompts (isCI = true) > multiselect > can set initial values 1`] = ` [ "[?25l", @@ -1424,6 +1564,46 @@ exports[`prompts (isCI = true) > multiselect > renders message 1`] = ` ] `; +exports[`prompts (isCI = true) > multiselect > renders multiple cancelled values 1`] = ` +[ + "[?25l", + "│ +◆ foo +│ ◻ opt0 +│ ◻ opt1 +│ ◻ opt2 +└ +", + "", + "", + "", + "│ ◼ opt0", + "", + "", + "", + "", + "│ ◼ opt0 +│ ◻ opt1 +│ ◻ opt2 +└ +", + "", + "", + "", + "│ ◼ opt1", + "", + "", + "", + "", + "■ foo +│ opt0, opt1 +│", + " +", + "[?25h", +] +`; + exports[`prompts (isCI = true) > multiselect > renders multiple selected options 1`] = ` [ "[?25l", diff --git a/packages/prompts/src/index.test.ts b/packages/prompts/src/index.test.ts index 39221225..0f177996 100644 --- a/packages/prompts/src/index.test.ts +++ b/packages/prompts/src/index.test.ts @@ -749,5 +749,68 @@ describe.each(['true', 'false'])('prompts (isCI = %s)', (isCI) => { expect(value).toEqual(['opt0']); expect(output.buffer).toMatchSnapshot(); }); + + test('can set custom labels', async () => { + const result = prompts.multiselect({ + message: 'foo', + options: [ + { value: 'opt0', label: 'Option 0' }, + { value: 'opt1', label: 'Option 1' }, + ], + input, + output, + }); + + input.emit('keypress', '', { name: 'space' }); + input.emit('keypress', '', { name: 'return' }); + + const value = await result; + + expect(value).toEqual(['opt0']); + expect(output.buffer).toMatchSnapshot(); + }); + + test('can render option hints', async () => { + const result = prompts.multiselect({ + message: 'foo', + options: [ + { value: 'opt0', hint: 'Hint 0' }, + { value: 'opt1', hint: 'Hint 1' }, + ], + input, + output, + }); + + input.emit('keypress', '', { name: 'space' }); + input.emit('keypress', '', { name: 'return' }); + + const value = await result; + + expect(value).toEqual(['opt0']); + expect(output.buffer).toMatchSnapshot(); + }); + + test('renders multiple cancelled values', async () => { + const result = prompts.multiselect({ + message: 'foo', + options: [ + { value: 'opt0' }, + { value: 'opt1' }, + { value: 'opt2' } + ], + input, + output, + }); + + input.emit('keypress', '', { name: 'space' }); + input.emit('keypress', '', { name: 'down' }); + input.emit('keypress', '', { name: 'space' }); + input.emit('keypress', '', { name: 'escape' }); + + const value = await result; + + expect(prompts.isCancel(value)).toBe(true); + expect(output.buffer).toMatchSnapshot(); + }); }); });