@@ -16,7 +16,6 @@ import {
16
16
import { QueryExecutionStatus } from '../types' ;
17
17
import { setResults } from '../slices' ;
18
18
import { Query , DataView } from 'src/plugins/data/common' ;
19
- import { DataPublicPluginStart } from '../../../../../../data/public' ;
20
19
import { ExploreServices } from '../../../../types' ;
21
20
import { SAMPLE_SIZE_SETTING } from '../../../../../common' ;
22
21
@@ -178,6 +177,9 @@ describe('Query Actions - Comprehensive Test Suite', () => {
178
177
query : {
179
178
queryString : {
180
179
getQuery : jest . fn ( ) . mockReturnValue ( { query : '' , language : 'PPL' } ) ,
180
+ getLanguageService : jest . fn ( ) . mockReturnValue ( {
181
+ getLanguage : jest . fn ( ) . mockReturnValue ( { } ) ,
182
+ } ) ,
181
183
} ,
182
184
filterManager : {
183
185
getFilters : jest . fn ( ) . mockReturnValue ( [ ] ) ,
@@ -488,7 +490,6 @@ describe('Query Actions - Comprehensive Test Suite', () => {
488
490
mockBuildPointSeriesData . mockReturnValue ( [ { x : 1609459200000 , y : 5 } ] as any ) ;
489
491
mockTabifyAggResponse . mockReturnValue ( { rows : [ ] , columns : [ ] } as any ) ;
490
492
} ) ;
491
-
492
493
it ( 'should process histogram data when timeFieldName exists' , ( ) => {
493
494
const rawResults = {
494
495
hits : {
@@ -793,7 +794,34 @@ describe('Query Actions - Comprehensive Test Suite', () => {
793
794
// Using mockCreateHistogramConfigs from module scope
794
795
mockCreateHistogramConfigs . mockReturnValue ( {
795
796
toDsl : jest . fn ( ) . mockReturnValue ( { } ) ,
797
+ aggs : [
798
+ { } as any ,
799
+ {
800
+ buckets : {
801
+ getInterval : jest . fn ( ( ) => ( { interval : '1h' , scale : 1 } ) ) ,
802
+ } ,
803
+ } as any ,
804
+ ] ,
796
805
} as any ) ;
806
+ mockSearchSource . fetch . mockReset ( ) ;
807
+ mockSearchSource . fetch . mockResolvedValue ( {
808
+ hits : {
809
+ hits : [
810
+ { _id : '1' , _source : { field1 : 'value1' } } ,
811
+ { _id : '2' , _source : { field2 : 'value2' } } ,
812
+ ] ,
813
+ total : 2 ,
814
+ } ,
815
+ took : 5 ,
816
+ aggregations : {
817
+ histogram : {
818
+ buckets : [
819
+ { key : 1609459200000 , doc_count : 5 } ,
820
+ { key : 1609462800000 , doc_count : 3 } ,
821
+ ] ,
822
+ } ,
823
+ } ,
824
+ } ) ;
797
825
} ) ;
798
826
799
827
it ( 'should execute histogram query with custom interval' , async ( ) => {
@@ -808,6 +836,17 @@ describe('Query Actions - Comprehensive Test Suite', () => {
808
836
809
837
expect ( mockServices . data . dataViews . get ) . toHaveBeenCalled ( ) ;
810
838
expect ( mockSearchSource . fetch ) . toHaveBeenCalled ( ) ;
839
+ expect ( mockDispatch ) . toHaveBeenCalledWith (
840
+ expect . objectContaining ( {
841
+ type : 'queryEditor/setIndividualQueryStatus' ,
842
+ payload : expect . objectContaining ( {
843
+ cacheKey : 'test-cache-key' ,
844
+ status : expect . objectContaining ( {
845
+ status : QueryExecutionStatus . READY ,
846
+ } ) ,
847
+ } ) ,
848
+ } )
849
+ ) ;
811
850
} ) ;
812
851
813
852
it ( 'should handle missing interval gracefully' , async ( ) => {
@@ -820,6 +859,18 @@ describe('Query Actions - Comprehensive Test Suite', () => {
820
859
await thunk ( mockDispatch , mockGetState , undefined ) ;
821
860
822
861
expect ( mockServices . data . dataViews . get ) . toHaveBeenCalled ( ) ;
862
+ expect ( mockSearchSource . fetch ) . toHaveBeenCalled ( ) ;
863
+ expect ( mockDispatch ) . toHaveBeenCalledWith (
864
+ expect . objectContaining ( {
865
+ type : 'queryEditor/setIndividualQueryStatus' ,
866
+ payload : expect . objectContaining ( {
867
+ cacheKey : 'test-cache-key' ,
868
+ status : expect . objectContaining ( {
869
+ status : QueryExecutionStatus . READY ,
870
+ } ) ,
871
+ } ) ,
872
+ } )
873
+ ) ;
823
874
} ) ;
824
875
825
876
it ( 'should handle dataView without timeFieldName' , async ( ) => {
@@ -834,16 +885,32 @@ describe('Query Actions - Comprehensive Test Suite', () => {
834
885
835
886
const thunk = executeHistogramQuery ( params ) ;
836
887
await thunk ( mockDispatch , mockGetState , undefined ) ;
837
-
888
+ expect ( mockServices . data . dataViews . get ) . toHaveBeenCalled ( ) ;
838
889
expect ( mockSearchSource . fetch ) . toHaveBeenCalled ( ) ;
890
+ expect ( mockDispatch ) . toHaveBeenCalledWith (
891
+ expect . objectContaining ( {
892
+ type : 'queryEditor/setIndividualQueryStatus' ,
893
+ payload : expect . objectContaining ( {
894
+ cacheKey : 'test-cache-key' ,
895
+ status : expect . objectContaining ( {
896
+ status : QueryExecutionStatus . READY ,
897
+ } ) ,
898
+ } ) ,
899
+ } )
900
+ ) ;
839
901
} ) ;
840
902
841
903
it ( 'should handle search errors gracefully' , async ( ) => {
842
904
const error = {
843
905
body : {
844
906
error : 'Search failed' ,
845
- message :
846
- '{"error":{"details":"Query syntax error","reason":"Invalid query","type":"parsing_exception"}}' ,
907
+ message : JSON . stringify ( {
908
+ error : {
909
+ details : 'Query syntax error' ,
910
+ reason : 'Invalid query' ,
911
+ type : 'parsing_exception' ,
912
+ } ,
913
+ } ) ,
847
914
statusCode : 400 ,
848
915
} ,
849
916
} ;
@@ -866,11 +933,20 @@ describe('Query Actions - Comprehensive Test Suite', () => {
866
933
// Verify error status is set in Redux
867
934
expect ( mockDispatch ) . toHaveBeenCalledWith (
868
935
expect . objectContaining ( {
869
- type : expect . stringContaining ( ' setIndividualQueryStatus') ,
936
+ type : 'queryEditor/ setIndividualQueryStatus',
870
937
payload : expect . objectContaining ( {
871
938
cacheKey : 'test-cache-key' ,
872
939
status : expect . objectContaining ( {
873
940
status : QueryExecutionStatus . ERROR ,
941
+ error : expect . objectContaining ( {
942
+ error : 'Search failed' ,
943
+ message : {
944
+ details : 'Query syntax error' ,
945
+ reason : 'Invalid query' ,
946
+ type : 'parsing_exception' ,
947
+ } ,
948
+ statusCode : 400 ,
949
+ } ) ,
874
950
} ) ,
875
951
} ) ,
876
952
} )
@@ -917,6 +993,17 @@ describe('Query Actions - Comprehensive Test Suite', () => {
917
993
918
994
const mockIndexPatterns = dataPublicModule . indexPatterns as any ;
919
995
mockIndexPatterns . isDefault . mockReturnValue ( true ) ;
996
+ mockSearchSource . fetch . mockReset ( ) ;
997
+ mockSearchSource . fetch . mockResolvedValue ( {
998
+ hits : {
999
+ hits : [
1000
+ { _id : '1' , _source : { field1 : 'value1' } } ,
1001
+ { _id : '2' , _source : { field2 : 'value2' } } ,
1002
+ ] ,
1003
+ total : 2 ,
1004
+ } ,
1005
+ took : 5 ,
1006
+ } ) ;
920
1007
} ) ;
921
1008
922
1009
it ( 'should execute tab query successfully' , async ( ) => {
@@ -931,6 +1018,17 @@ describe('Query Actions - Comprehensive Test Suite', () => {
931
1018
expect ( mockServices . data . dataViews . get ) . toHaveBeenCalled ( ) ;
932
1019
expect ( mockSearchSource . fetch ) . toHaveBeenCalled ( ) ;
933
1020
expect ( setResults ) . toHaveBeenCalled ( ) ;
1021
+ expect ( mockDispatch ) . toHaveBeenCalledWith (
1022
+ expect . objectContaining ( {
1023
+ type : 'queryEditor/setIndividualQueryStatus' ,
1024
+ payload : expect . objectContaining ( {
1025
+ cacheKey : 'test-cache-key' ,
1026
+ status : expect . objectContaining ( {
1027
+ status : QueryExecutionStatus . READY ,
1028
+ } ) ,
1029
+ } ) ,
1030
+ } )
1031
+ ) ;
934
1032
} ) ;
935
1033
936
1034
it ( 'should handle missing services gracefully' , async ( ) => {
0 commit comments