@@ -7,38 +7,32 @@ import { defaultRequestSpec } from '../../../src/RequestSpec';
77import { CmkQuery } from '../../../src/types' ;
88import { QueryEditor } from '../../../src/ui/QueryEditor' ;
99
10- const completions : Record < string , string [ ] [ ] > = {
10+ const completions : Record < string , Array < { value : string ; label : string } > > = {
1111 sites : [
12- [ 'site_1' , 'Site One' ] ,
13- [ 'site_2' , 'Site Two' ] ,
12+ { value : 'site_1' , label : 'Site One' } ,
13+ { value : 'site_2' , label : 'Site Two' } ,
1414 ] ,
1515 monitored_hostname : [
16- [ 'host_name_1' , 'Hostname One' ] ,
17- [ 'host_name_2' , 'Hostname Two' ] ,
16+ { value : 'host_name_1' , label : 'Hostname One' } ,
17+ { value : 'host_name_2' , label : 'Hostname Two' } ,
1818 ] ,
1919 monitored_service_description : [
20- [ 'service_1' , 'Service One' ] ,
21- [ 'service_2' , 'Service Two' ] ,
20+ { value : 'service_1' , label : 'Service One' } ,
21+ { value : 'service_2' , label : 'Service Two' } ,
2222 ] ,
2323 monitored_metrics : [
24- [ 'metric_1' , 'Metric One' ] ,
25- [ 'metric_2' , 'Metric Two' ] ,
24+ { value : 'metric_1' , label : 'Metric One' } ,
25+ { value : 'metric_2' , label : 'Metric Two' } ,
2626 ] ,
2727 available_graphs : [
28- [ 'graph_1' , 'Graph One' ] ,
29- [ 'graph_2' , 'Graph Two' ] ,
28+ { value : 'graph_1' , label : 'Graph One' } ,
29+ { value : 'graph_2' , label : 'Graph Two' } ,
3030 ] ,
3131} ;
3232
3333describe ( 'QueryEditor RAW' , ( ) => {
34- const autocompleterRequest = jest . fn ( async ( _ , { ident } ) => {
35- return {
36- data : {
37- result : {
38- choices : completions [ ident ] ,
39- } ,
40- } ,
41- } ;
34+ const contextAutocomplete = jest . fn ( async ( ident , _partialRequestSpec , _prefix , _params ) => {
35+ return completions [ ident ] ;
4236 } ) ;
4337
4438 const mockDatasource = {
@@ -47,7 +41,7 @@ describe('QueryEditor RAW', () => {
4741 edition : 'RAW' ,
4842 } ,
4943 } ,
50- autocompleterRequest ,
44+ contextAutocomplete ,
5145 getEdition ( ) {
5246 return 'RAW' ;
5347 } ,
@@ -75,9 +69,11 @@ describe('QueryEditor RAW', () => {
7569 async ( { label, attribute, autocomplete } ) => {
7670 render ( < QueryEditor datasource = { mockDatasource } query = { query } onRunQuery = { onRunQuery } onChange = { onChange } /> ) ;
7771
78- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
79- 'ajax_vs_autocomplete.py' ,
80- expect . objectContaining ( { ident : autocomplete } )
72+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
73+ autocomplete ,
74+ expect . anything ( ) ,
75+ expect . anything ( ) ,
76+ expect . anything ( )
8177 ) ;
8278
8379 const input = screen . getByLabelText ( label ) ;
@@ -140,70 +136,85 @@ describe('QueryEditor RAW', () => {
140136 it ( 'calls the autocompleters the minimal amount of times' , async ( ) => {
141137 render ( < QueryEditor datasource = { mockDatasource } query = { query } onRunQuery = { onRunQuery } onChange = { onChange } /> ) ;
142138
143- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
144- 'ajax_vs_autocomplete.py' ,
145- expect . objectContaining ( { ident : 'sites' } )
146- ) ;
147- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
148- 'ajax_vs_autocomplete.py' ,
149- expect . objectContaining ( { ident : 'monitored_hostname' } )
139+ expect ( contextAutocomplete ) . toHaveBeenCalledWith ( 'sites' , expect . anything ( ) , expect . anything ( ) , expect . anything ( ) ) ;
140+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
141+ 'monitored_hostname' ,
142+ expect . anything ( ) ,
143+ expect . anything ( ) ,
144+ expect . anything ( )
150145 ) ;
151- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
152- 'ajax_vs_autocomplete.py' ,
153- expect . objectContaining ( { ident : 'monitored_service_description' } )
146+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
147+ 'monitored_service_description' ,
148+ expect . anything ( ) ,
149+ expect . anything ( ) ,
150+ expect . anything ( )
154151 ) ;
155- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
156- 'ajax_vs_autocomplete.py' ,
157- expect . objectContaining ( { ident : 'available_graphs' } )
152+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
153+ 'available_graphs' ,
154+ expect . anything ( ) ,
155+ expect . anything ( ) ,
156+ expect . anything ( )
158157 ) ;
159- autocompleterRequest . mockClear ( ) ;
158+ contextAutocomplete . mockClear ( ) ;
160159
161160 const siteInput = screen . getByLabelText ( 'Site' ) ;
162161 await act ( async ( ) => {
163162 await selectEvent . select ( siteInput , 'Site One' , { container : document . body } ) ;
164163 } ) ;
165- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
166- 'ajax_vs_autocomplete.py' ,
167- expect . objectContaining ( { ident : 'monitored_hostname' } )
164+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
165+ 'monitored_hostname' ,
166+ expect . anything ( ) ,
167+ expect . anything ( ) ,
168+ expect . anything ( )
168169 ) ;
169- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
170- 'ajax_vs_autocomplete.py' ,
171- expect . objectContaining ( { ident : 'monitored_service_description' } )
170+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
171+ 'monitored_service_description' ,
172+ expect . anything ( ) ,
173+ expect . anything ( ) ,
174+ expect . anything ( )
172175 ) ;
173- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
174- 'ajax_vs_autocomplete.py' ,
175- expect . objectContaining ( { ident : 'available_graphs' } )
176+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
177+ 'available_graphs' ,
178+ expect . anything ( ) ,
179+ expect . anything ( ) ,
180+ expect . anything ( )
176181 ) ;
177- autocompleterRequest . mockClear ( ) ;
182+ contextAutocomplete . mockClear ( ) ;
178183
179184 const hostInput = screen . getByLabelText ( 'Hostname' ) ;
180185 await act ( async ( ) => {
181186 await selectEvent . select ( hostInput , 'Hostname One' , { container : document . body } ) ;
182187 } ) ;
183- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
184- 'ajax_vs_autocomplete.py' ,
185- expect . objectContaining ( { ident : 'monitored_service_description' } )
188+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
189+ 'monitored_service_description' ,
190+ expect . anything ( ) ,
191+ expect . anything ( ) ,
192+ expect . anything ( )
186193 ) ;
187- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
188- 'ajax_vs_autocomplete.py' ,
189- expect . objectContaining ( { ident : 'available_graphs' } )
194+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
195+ 'available_graphs' ,
196+ expect . anything ( ) ,
197+ expect . anything ( ) ,
198+ expect . anything ( )
190199 ) ;
191- autocompleterRequest . mockClear ( ) ;
200+ contextAutocomplete . mockClear ( ) ;
192201
193202 const serviceInput = screen . getByLabelText ( 'Service' ) ;
194203 await act ( async ( ) => {
195204 await selectEvent . select ( serviceInput , 'Service One' , { container : document . body } ) ;
196205 } ) ;
197- expect ( autocompleterRequest ) . toHaveBeenCalledWith (
198- 'ajax_vs_autocomplete.py' ,
199- expect . objectContaining ( { ident : 'available_graphs' } )
206+ expect ( contextAutocomplete ) . toHaveBeenCalledWith (
207+ 'available_graphs' ,
208+ expect . anything ( ) ,
209+ expect . anything ( ) ,
210+ expect . anything ( )
200211 ) ;
201- autocompleterRequest . mockClear ( ) ;
212+ contextAutocomplete . mockClear ( ) ;
202213
203214 const graphInput = screen . getByLabelText ( 'Predefined graph' ) ;
204215 await act ( async ( ) => {
205216 await selectEvent . select ( graphInput , 'Graph One' , { container : document . body } ) ;
206217 } ) ;
207- expect ( autocompleterRequest ) . toHaveBeenCalledTimes ( 0 ) ;
218+ expect ( contextAutocomplete ) . toHaveBeenCalledTimes ( 0 ) ;
208219 } ) ;
209220} ) ;
0 commit comments