@@ -76,12 +76,25 @@ describe("AutoCompleteAdapter", () => {
76
76
let server : ActiveServer
77
77
let autoCompleteAdapter : AutoCompleteAdapter
78
78
79
- async function getResults (
79
+ type getSuggestionParams = Parameters < typeof autoCompleteAdapter . getSuggestions >
80
+
81
+ /** Function that stubs `server.connection.completion` and returns the `autoCompleteAdapter.getSuggestions(...)` */
82
+ async function getSuggestionsMock (
80
83
items : CompletionItem [ ] ,
81
- requestParams : { prefix ?: string ; point ?: Point }
84
+ requestParams : Parameters < typeof createRequest > [ 0 ] ,
85
+ onDidConvertCompletionItem ?: getSuggestionParams [ 2 ] ,
86
+ minimumWordLength ?: getSuggestionParams [ 3 ] ,
82
87
) : Promise < ac . AnySuggestion [ ] > {
83
- sinon . stub ( server . connection , "completion" ) . resolves ( items )
84
- return autoCompleteAdapter . getSuggestions ( server , createRequest ( requestParams ) )
88
+ const resultsSandBox = sinon . createSandbox ( )
89
+ resultsSandBox . stub ( server . connection , "completion" ) . resolves ( items )
90
+ const results = autoCompleteAdapter . getSuggestions (
91
+ server ,
92
+ createRequest ( requestParams ) ,
93
+ onDidConvertCompletionItem ,
94
+ minimumWordLength ,
95
+ )
96
+ resultsSandBox . restore ( )
97
+ return results
85
98
}
86
99
87
100
beforeEach ( ( ) => {
@@ -90,12 +103,12 @@ describe("AutoCompleteAdapter", () => {
90
103
} )
91
104
92
105
it ( "gets AutoComplete suggestions via LSP given an AutoCompleteRequest" , async ( ) => {
93
- const results = await getResults ( completionItems , { prefix : "" } )
106
+ const results = await getSuggestionsMock ( completionItems , { prefix : "" } )
94
107
expect ( results . length ) . equals ( completionItems . length )
95
108
} )
96
109
97
110
it ( "provides a filtered selection based on the filterKey" , async ( ) => {
98
- const results = await getResults ( completionItems , { prefix : "lab" } )
111
+ const results = await getSuggestionsMock ( completionItems , { prefix : "lab" } )
99
112
expect ( results . length ) . equals ( 2 )
100
113
expect ( results . some ( ( r ) => r . displayText === "thisHasFiltertext" ) ) . to . be . true
101
114
expect ( results . some ( ( r ) => r . displayText === "label3" ) ) . to . be . true
@@ -107,7 +120,7 @@ describe("AutoCompleteAdapter", () => {
107
120
{ label : "b" } ,
108
121
{ label : "c" , sortText : "a" } ,
109
122
]
110
- const results = await getResults ( sortedItems , { prefix : "" } )
123
+ const results = await getSuggestionsMock ( sortedItems , { prefix : "" } )
111
124
112
125
expect ( results . length ) . equals ( sortedItems . length )
113
126
expect ( results [ 0 ] . displayText ) . equals ( "c" )
@@ -116,7 +129,7 @@ describe("AutoCompleteAdapter", () => {
116
129
} )
117
130
118
131
it ( "uses the filterText property to arrange completions when there is a prefix" , async ( ) => {
119
- const results = await getResults ( completionItems , { prefix : "lab" } )
132
+ const results = await getSuggestionsMock ( completionItems , { prefix : "lab" } )
120
133
expect ( results . length ) . equals ( 2 )
121
134
expect ( results [ 0 ] . displayText ) . equals ( "label3" ) // shorter than 'labrador', so expected to be first
122
135
expect ( results [ 1 ] . displayText ) . equals ( "thisHasFiltertext" )
0 commit comments