@@ -62,28 +62,23 @@ const defaultRequest = {
6262 startTime : 0 ,
6363} ;
6464
65- const setupDatasourceWithAsyncBackend = ( {
66- settings = defaultInstanceSettings ,
67- asyncQueryDataSupport = true ,
68- } : {
69- settings ?: DataSourceInstanceSettings < { } > ;
70- asyncQueryDataSupport ?: boolean ;
71- } ) => new DatasourceWithAsyncBackend < DataQuery > ( settings , asyncQueryDataSupport ) ;
65+ const setupDatasourceWithAsyncBackend = ( settings : DataSourceInstanceSettings = defaultInstanceSettings ) =>
66+ new DatasourceWithAsyncBackend < DataQuery > ( settings ) ;
7267
7368describe ( 'DatasourceWithAsyncBackend' , ( ) => {
7469 // beforeAll(() => {
7570 // queryMock.mockClear();
7671 // });
7772
7873 it ( 'can store running queries' , ( ) => {
79- const ds = setupDatasourceWithAsyncBackend ( { } ) ;
74+ const ds = setupDatasourceWithAsyncBackend ( ) ;
8075
8176 ds . storeQuery ( defaultQuery , { queryID : '123' } ) ;
8277 expect ( ds . getQuery ( defaultQuery ) ) . toEqual ( { queryID : '123' } ) ;
8378 } ) ;
8479
8580 it ( 'can remove running queries' , ( ) => {
86- const ds = setupDatasourceWithAsyncBackend ( { } ) ;
81+ const ds = setupDatasourceWithAsyncBackend ( ) ;
8782
8883 ds . storeQuery ( defaultQuery , { queryID : '123' } ) ;
8984 expect ( ds . getQuery ( defaultQuery ) ) . toEqual ( { queryID : '123' } ) ;
@@ -92,15 +87,15 @@ describe('DatasourceWithAsyncBackend', () => {
9287 } ) ;
9388
9489 it ( 'can cancel running queries' , ( ) => {
95- const ds = setupDatasourceWithAsyncBackend ( { } ) ;
90+ const ds = setupDatasourceWithAsyncBackend ( ) ;
9691
9792 ds . storeQuery ( defaultQuery , { queryID : '123' } ) ;
9893 ds . cancel ( defaultQuery ) ;
9994 expect ( ds . getQuery ( defaultQuery ) ) . toEqual ( { queryID : '123' , shouldCancel : true } ) ;
10095 } ) ;
10196
102- it ( 'can queue individual queries to run asynchronously if feature toggle asyncQueryDataSupport is `true` ' , ( ) => {
103- const ds = setupDatasourceWithAsyncBackend ( { asyncQueryDataSupport : true } ) ;
97+ it ( 'will queue individual queries to run asynchronously' , ( ) => {
98+ const ds = setupDatasourceWithAsyncBackend ( ) ;
10499
105100 ds . doSingle = jest . fn ( ) . mockReturnValue ( Promise . resolve ( { data : [ ] } ) ) ;
106101 expect ( ds . doSingle ) . not . toHaveBeenCalled ( ) ;
@@ -110,19 +105,8 @@ describe('DatasourceWithAsyncBackend', () => {
110105 expect ( ds . doSingle ) . toHaveBeenCalledWith ( defaultQuery2 , defaultRequest ) ;
111106 } ) ;
112107
113- it ( 'can run queries synchronously if feature toggle asyncQueryDataSupport is `false`' , ( ) => {
114- const ds = setupDatasourceWithAsyncBackend ( { asyncQueryDataSupport : false } ) ;
115-
116- ds . doSingle = jest . fn ( ) ;
117- expect ( ds . doSingle ) . not . toHaveBeenCalled ( ) ;
118- ds . query ( defaultRequest ) ;
119- expect ( ds . doSingle ) . not . toHaveBeenCalled ( ) ;
120- expect ( queryMock ) . toHaveBeenCalledTimes ( 1 ) ;
121- expect ( queryMock ) . toHaveBeenCalledWith ( defaultRequest ) ;
122- } ) ;
123-
124108 it ( 'uses the datasource id for the request id' , ( ) => {
125- const ds = setupDatasourceWithAsyncBackend ( { asyncQueryDataSupport : true } ) ;
109+ const ds = setupDatasourceWithAsyncBackend ( ) ;
126110 expect ( getRequestLooperMock ) . not . toHaveBeenCalled ( ) ;
127111 ds . doSingle ( defaultQuery , defaultRequest ) ;
128112 expect ( getRequestLooperMock ) . toHaveBeenCalledTimes ( 1 ) ;
0 commit comments