Skip to content

Commit 4a6b598

Browse files
committed
test: add mixed size re-render test
1 parent 97bb161 commit 4a6b598

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

packages/prompts/test/__snapshots__/select.test.ts.snap

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,44 @@ exports[`select (isCI = false) > down arrow selects next option 1`] = `
6363
]
6464
`;
6565
66+
exports[`select (isCI = false) > handles mixed size re-renders 1`] = `
67+
[
68+
"<cursor.hide>",
69+
"│
70+
◆ Whatever
71+
│ ● Long Option
72+
│ Long Option
73+
│ Long Option
74+
│ Long Option
75+
│ Long Option
76+
│ Long Option
77+
│ Long Option
78+
│ Long Option
79+
│ ...
80+
└
81+
",
82+
"<cursor.backward count=999><cursor.up count=12>",
83+
"<erase.down>",
84+
"│
85+
◆ Whatever
86+
│ ...
87+
│ ○ Option 0
88+
│ ○ Option 1
89+
│ ○ Option 2
90+
│ ● Option 3
91+
└
92+
",
93+
"<cursor.backward count=999><cursor.up count=8>",
94+
"<cursor.down count=1>",
95+
"<erase.down>",
96+
"◇ Whatever
97+
│ Option 3",
98+
"
99+
",
100+
"<cursor.show>",
101+
]
102+
`;
103+
66104
exports[`select (isCI = false) > renders disabled options 1`] = `
67105
[
68106
"<cursor.hide>",
@@ -298,6 +336,44 @@ exports[`select (isCI = true) > down arrow selects next option 1`] = `
298336
]
299337
`;
300338
339+
exports[`select (isCI = true) > handles mixed size re-renders 1`] = `
340+
[
341+
"<cursor.hide>",
342+
"│
343+
◆ Whatever
344+
│ ● Long Option
345+
│ Long Option
346+
│ Long Option
347+
│ Long Option
348+
│ Long Option
349+
│ Long Option
350+
│ Long Option
351+
│ Long Option
352+
│ ...
353+
└
354+
",
355+
"<cursor.backward count=999><cursor.up count=12>",
356+
"<erase.down>",
357+
"│
358+
◆ Whatever
359+
│ ...
360+
│ ○ Option 0
361+
│ ○ Option 1
362+
│ ○ Option 2
363+
│ ● Option 3
364+
└
365+
",
366+
"<cursor.backward count=999><cursor.up count=8>",
367+
"<cursor.down count=1>",
368+
"<erase.down>",
369+
"◇ Whatever
370+
│ Option 3",
371+
"
372+
",
373+
"<cursor.show>",
374+
]
375+
`;
376+
301377
exports[`select (isCI = true) > renders disabled options 1`] = `
302378
[
303379
"<cursor.hide>",

packages/prompts/test/select.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,31 @@ describe.each(['true', 'false'])('select (isCI = %s)', (isCI) => {
211211

212212
expect(output.buffer).toMatchSnapshot();
213213
});
214+
215+
test('handles mixed size re-renders', async () => {
216+
output.rows = 10;
217+
218+
const result = prompts.select({
219+
message: 'Whatever',
220+
options: [
221+
{
222+
value: 'longopt',
223+
label: Array.from({ length: 8 }, () => 'Long Option').join('\n'),
224+
},
225+
...Array.from({ length: 4 }, (_, i) => ({
226+
value: `opt${i}`,
227+
label: `Option ${i}`,
228+
})),
229+
],
230+
input,
231+
output,
232+
});
233+
234+
input.emit('keypress', '', { name: 'up' });
235+
input.emit('keypress', '', { name: 'return' });
236+
237+
await result;
238+
239+
expect(output.buffer).toMatchSnapshot();
240+
});
214241
});

0 commit comments

Comments
 (0)