Skip to content

Commit bc94a11

Browse files
committed
test: add tests for labels/hints in select
1 parent e6fc1b6 commit bc94a11

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

packages/prompts/src/__snapshots__/index.test.ts.snap

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,31 @@ exports[`prompts (isCI = false) > multiselect > can cancel 1`] = `
169169
]
170170
`;
171171

172+
exports[`prompts (isCI = false) > multiselect > can render option hints 1`] = `
173+
[
174+
"[?25l",
175+
"│
176+
◆ foo
177+
│ ◻ opt0 (Hint 0)
178+
│ ◻ opt1
179+
└
180+
",
181+
"",
182+
"",
183+
"",
184+
"│ ◼ opt0 (Hint 0)",
185+
"",
186+
"",
187+
"",
188+
"",
189+
"◇ foo
190+
│ opt0",
191+
"
192+
",
193+
"[?25h",
194+
]
195+
`;
196+
172197
exports[`prompts (isCI = false) > multiselect > can set cursorAt to preselect an option 1`] = `
173198
[
174199
"[?25l",
@@ -194,6 +219,31 @@ exports[`prompts (isCI = false) > multiselect > can set cursorAt to preselect an
194219
]
195220
`;
196221

222+
exports[`prompts (isCI = false) > multiselect > can set custom labels 1`] = `
223+
[
224+
"[?25l",
225+
"│
226+
◆ foo
227+
│ ◻ Option 0
228+
│ ◻ Option 1
229+
└
230+
",
231+
"",
232+
"",
233+
"",
234+
"│ ◼ Option 0",
235+
"",
236+
"",
237+
"",
238+
"",
239+
"◇ foo
240+
│ Option 0",
241+
"
242+
",
243+
"[?25h",
244+
]
245+
`;
246+
197247
exports[`prompts (isCI = false) > multiselect > can set initial values 1`] = `
198248
[
199249
"[?25l",
@@ -1244,6 +1294,31 @@ exports[`prompts (isCI = true) > multiselect > can cancel 1`] = `
12441294
]
12451295
`;
12461296

1297+
exports[`prompts (isCI = true) > multiselect > can render option hints 1`] = `
1298+
[
1299+
"[?25l",
1300+
"│
1301+
◆ foo
1302+
│ ◻ opt0 (Hint 0)
1303+
│ ◻ opt1
1304+
└
1305+
",
1306+
"",
1307+
"",
1308+
"",
1309+
"│ ◼ opt0 (Hint 0)",
1310+
"",
1311+
"",
1312+
"",
1313+
"",
1314+
"◇ foo
1315+
│ opt0",
1316+
"
1317+
",
1318+
"[?25h",
1319+
]
1320+
`;
1321+
12471322
exports[`prompts (isCI = true) > multiselect > can set cursorAt to preselect an option 1`] = `
12481323
[
12491324
"[?25l",
@@ -1269,6 +1344,31 @@ exports[`prompts (isCI = true) > multiselect > can set cursorAt to preselect an
12691344
]
12701345
`;
12711346

1347+
exports[`prompts (isCI = true) > multiselect > can set custom labels 1`] = `
1348+
[
1349+
"[?25l",
1350+
"│
1351+
◆ foo
1352+
│ ◻ Option 0
1353+
│ ◻ Option 1
1354+
└
1355+
",
1356+
"",
1357+
"",
1358+
"",
1359+
"│ ◼ Option 0",
1360+
"",
1361+
"",
1362+
"",
1363+
"",
1364+
"◇ foo
1365+
│ Option 0",
1366+
"
1367+
",
1368+
"[?25h",
1369+
]
1370+
`;
1371+
12721372
exports[`prompts (isCI = true) > multiselect > can set initial values 1`] = `
12731373
[
12741374
"[?25l",

packages/prompts/src/index.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,5 +749,45 @@ describe.each(['true', 'false'])('prompts (isCI = %s)', (isCI) => {
749749
expect(value).toEqual(['opt0']);
750750
expect(output.buffer).toMatchSnapshot();
751751
});
752+
753+
test('can set custom labels', async () => {
754+
const result = prompts.multiselect({
755+
message: 'foo',
756+
options: [
757+
{ value: 'opt0', label: 'Option 0' },
758+
{ value: 'opt1', label: 'Option 1' },
759+
],
760+
input,
761+
output,
762+
});
763+
764+
input.emit('keypress', '', { name: 'space' });
765+
input.emit('keypress', '', { name: 'return' });
766+
767+
const value = await result;
768+
769+
expect(value).toEqual(['opt0']);
770+
expect(output.buffer).toMatchSnapshot();
771+
});
772+
773+
test('can render option hints', async () => {
774+
const result = prompts.multiselect({
775+
message: 'foo',
776+
options: [
777+
{ value: 'opt0', hint: 'Hint 0' },
778+
{ value: 'opt1', hint: 'Hint 1' },
779+
],
780+
input,
781+
output,
782+
});
783+
784+
input.emit('keypress', '', { name: 'space' });
785+
input.emit('keypress', '', { name: 'return' });
786+
787+
const value = await result;
788+
789+
expect(value).toEqual(['opt0']);
790+
expect(output.buffer).toMatchSnapshot();
791+
});
752792
});
753793
});

0 commit comments

Comments
 (0)