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
180 changes: 180 additions & 0 deletions packages/prompts/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
63 changes: 63 additions & 0 deletions packages/prompts/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});