@@ -187,4 +187,78 @@ describe("promptForSelection", () => {
187187 const result = await promptForSelection ( "Select:" , choices ) ;
188188 expect ( result ) . toBeNull ( ) ;
189189 } ) ;
190+
191+ describe ( "separators" , ( ) => {
192+ it ( "renders separator entries un-numbered with single-space prefix" , async ( ) => {
193+ mockQuestion = ( _query , callback ) => callback ( "1" ) ;
194+ await promptForSelection ( "Select an account:" , [
195+ { separator : "── Local accounts ──" } ,
196+ { name : "prod" , value : "prod" } ,
197+ { name : "staging" , value : "staging" } ,
198+ { separator : "── Other accounts ──" } ,
199+ { name : "external" , value : "external" } ,
200+ ] ) ;
201+
202+ // Separators: single leading space, no [N] marker (matches inquirer's render)
203+ expect ( mockWrite ) . toHaveBeenCalledWith ( " ── Local accounts ──\n" ) ;
204+ expect ( mockWrite ) . toHaveBeenCalledWith ( " ── Other accounts ──\n" ) ;
205+ // Selectable items numbered sequentially, ignoring separators
206+ expect ( mockWrite ) . toHaveBeenCalledWith ( " [1] prod\n" ) ;
207+ expect ( mockWrite ) . toHaveBeenCalledWith ( " [2] staging\n" ) ;
208+ expect ( mockWrite ) . toHaveBeenCalledWith ( " [3] external\n" ) ;
209+ } ) ;
210+
211+ it ( "numbers only selectable items so '1' picks the first selectable" , async ( ) => {
212+ mockQuestion = ( _query , callback ) => callback ( "1" ) ;
213+ const result = await promptForSelection < string > ( "Pick:" , [
214+ { separator : "── Section ──" } ,
215+ { name : "first" , value : "first" } ,
216+ { name : "second" , value : "second" } ,
217+ ] ) ;
218+ expect ( result ) . toBe ( "first" ) ;
219+ } ) ;
220+
221+ it ( "rejects out-of-range numbers based on selectable count, not total entries" , async ( ) => {
222+ // 2 selectables + 2 separators = 4 entries. "3" must be rejected.
223+ let callCount = 0 ;
224+ mockQuestion = ( _query , callback ) => {
225+ callCount ++ ;
226+ if ( callCount === 1 ) {
227+ callback ( "3" ) ;
228+ } else {
229+ callback ( "2" ) ;
230+ }
231+ } ;
232+ const result = await promptForSelection < string > ( "Pick:" , [
233+ { separator : "── A ──" } ,
234+ { name : "first" , value : "first" } ,
235+ { separator : "── B ──" } ,
236+ { name : "second" , value : "second" } ,
237+ ] ) ;
238+ expect ( result ) . toBe ( "second" ) ;
239+ expect ( callCount ) . toBe ( 2 ) ;
240+ expect ( mockWrite ) . toHaveBeenCalledWith (
241+ "Invalid selection. Enter a number between 1 and 2.\n" ,
242+ ) ;
243+ } ) ;
244+
245+ it ( "returns null when choices contain only separators (no selectables)" , async ( ) => {
246+ const result = await promptForSelection ( "Pick:" , [
247+ { separator : "── A ──" } ,
248+ { separator : "── B ──" } ,
249+ ] ) ;
250+ expect ( result ) . toBeNull ( ) ;
251+ expect ( mockWrite ) . not . toHaveBeenCalled ( ) ;
252+ } ) ;
253+
254+ it ( "supports separators interleaved at any position" , async ( ) => {
255+ mockQuestion = ( _query , callback ) => callback ( "2" ) ;
256+ const result = await promptForSelection < string > ( "Pick:" , [
257+ { name : "alpha" , value : "alpha" } ,
258+ { separator : "── divider ──" } ,
259+ { name : "beta" , value : "beta" } ,
260+ ] ) ;
261+ expect ( result ) . toBe ( "beta" ) ;
262+ } ) ;
263+ } ) ;
190264} ) ;
0 commit comments