@@ -9,7 +9,7 @@ import { useClickhouseClient } from '@/clickhouse';
9
9
10
10
import {
11
11
getGranularityAlignedTimeWindows ,
12
- useQueriedChartConfig ,
12
+ useChunkedQueriedChartConfig ,
13
13
} from '../useChartConfig' ;
14
14
15
15
// Mock the clickhouse module
@@ -97,6 +97,48 @@ describe('useChartConfig', () => {
97
97
) . toEqual ( [ undefined ] ) ;
98
98
} ) ;
99
99
100
+ it ( 'returns windows aligned to the granularity if the granularity is auto' , ( ) => {
101
+ expect (
102
+ getGranularityAlignedTimeWindows (
103
+ {
104
+ dateRange : [
105
+ new Date ( '2023-01-10 00:00:00' ) ,
106
+ new Date ( '2023-01-10 01:00:00' ) ,
107
+ ] ,
108
+ granularity : 'auto' , // will be 1 minute
109
+ timestampValueExpression : 'TimestampTime' ,
110
+ } as ChartConfigWithOptDateRange ,
111
+ [
112
+ 30 , // 30s
113
+ 5 * 60 , // 5m
114
+ 60 * 60 , // 1hr
115
+ ] ,
116
+ ) ,
117
+ ) . toEqual ( [
118
+ {
119
+ dateRange : [
120
+ new Date ( '2023-01-10 00:59:00' ) , // Aligned to minute, the auto-inferred granularity
121
+ new Date ( '2023-01-10 01:00:00' ) ,
122
+ ] ,
123
+ dateRangeEndInclusive : undefined ,
124
+ } ,
125
+ {
126
+ dateRange : [
127
+ new Date ( '2023-01-10 00:54:00' ) ,
128
+ new Date ( '2023-01-10 00:59:00' ) ,
129
+ ] ,
130
+ dateRangeEndInclusive : false ,
131
+ } ,
132
+ {
133
+ dateRange : [
134
+ new Date ( '2023-01-10 00:00:00' ) ,
135
+ new Date ( '2023-01-10 00:54:00' ) ,
136
+ ] ,
137
+ dateRangeEndInclusive : false ,
138
+ } ,
139
+ ] ) ;
140
+ } ) ;
141
+
100
142
it ( 'returns windows aligned to the granularity if the granularity is larger than the window size' , ( ) => {
101
143
expect (
102
144
getGranularityAlignedTimeWindows (
@@ -269,7 +311,7 @@ describe('useChartConfig', () => {
269
311
} ) ;
270
312
} ) ;
271
313
272
- describe ( 'useQueriedChartConfig ' , ( ) => {
314
+ describe ( 'useChunkedQueriedChartConfig ' , ( ) => {
273
315
let queryClient : QueryClient ;
274
316
let wrapper : React . ComponentType < { children : any } > ;
275
317
let mockClickhouseClient : jest . Mocked < ClickhouseClient > ;
@@ -319,9 +361,12 @@ describe('useChartConfig', () => {
319
361
320
362
mockClickhouseClient . queryChartConfig . mockResolvedValue ( mockResponse ) ;
321
363
322
- const { result } = renderHook ( ( ) => useQueriedChartConfig ( config ) , {
323
- wrapper,
324
- } ) ;
364
+ const { result } = renderHook (
365
+ ( ) => useChunkedQueriedChartConfig ( config ) ,
366
+ {
367
+ wrapper,
368
+ } ,
369
+ ) ;
325
370
326
371
await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBe ( true ) ) ;
327
372
await waitFor ( ( ) => expect ( result . current . isFetching ) . toBe ( false ) ) ;
@@ -364,9 +409,12 @@ describe('useChartConfig', () => {
364
409
365
410
mockClickhouseClient . queryChartConfig . mockResolvedValue ( mockResponse ) ;
366
411
367
- const { result } = renderHook ( ( ) => useQueriedChartConfig ( config ) , {
368
- wrapper,
369
- } ) ;
412
+ const { result } = renderHook (
413
+ ( ) => useChunkedQueriedChartConfig ( config ) ,
414
+ {
415
+ wrapper,
416
+ } ,
417
+ ) ;
370
418
371
419
await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBe ( true ) ) ;
372
420
await waitFor ( ( ) => expect ( result . current . isFetching ) . toBe ( false ) ) ;
@@ -413,55 +461,8 @@ describe('useChartConfig', () => {
413
461
414
462
mockClickhouseClient . queryChartConfig . mockResolvedValue ( mockResponse ) ;
415
463
416
- const { result } = renderHook ( ( ) => useQueriedChartConfig ( config ) , {
417
- wrapper,
418
- } ) ;
419
-
420
- await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBe ( true ) ) ;
421
- await waitFor ( ( ) => expect ( result . current . isFetching ) . toBe ( false ) ) ;
422
-
423
- // Should only be called once since chunking is disabled without timestampValueExpression
424
- expect ( mockClickhouseClient . queryChartConfig ) . toHaveBeenCalledTimes ( 1 ) ;
425
- expect ( mockClickhouseClient . queryChartConfig ) . toHaveBeenCalledWith ( {
426
- config,
427
- metadata : expect . any ( Object ) ,
428
- opts : {
429
- abort_signal : expect . any ( AbortSignal ) ,
430
- } ,
431
- } ) ;
432
- expect ( result . current . data ) . toEqual ( {
433
- data : mockResponse . data ,
434
- meta : mockResponse . meta ,
435
- rows : mockResponse . rows ,
436
- } ) ;
437
- } ) ;
438
-
439
- it ( 'fetches data without chunking when disableQueryChunking is true' , async ( ) => {
440
- const config = createMockChartConfig ( {
441
- dateRange : [
442
- new Date ( '2025-10-01 00:00:00Z' ) ,
443
- new Date ( '2025-10-02 00:00:00Z' ) ,
444
- ] ,
445
- granularity : '1 hour' ,
446
- } ) ;
447
-
448
- const mockResponse = createMockQueryResponse ( [
449
- {
450
- 'count()' : '71' ,
451
- SeverityText : 'info' ,
452
- __hdx_time_bucket : '2025-10-01T00:00:00Z' ,
453
- } ,
454
- {
455
- 'count()' : '73' ,
456
- SeverityText : 'info' ,
457
- __hdx_time_bucket : '2025-10-02T00:00:00Z' ,
458
- } ,
459
- ] ) ;
460
-
461
- mockClickhouseClient . queryChartConfig . mockResolvedValue ( mockResponse ) ;
462
-
463
464
const { result } = renderHook (
464
- ( ) => useQueriedChartConfig ( config , { disableQueryChunking : true } ) ,
465
+ ( ) => useChunkedQueriedChartConfig ( config ) ,
465
466
{
466
467
wrapper,
467
468
} ,
@@ -470,7 +471,7 @@ describe('useChartConfig', () => {
470
471
await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBe ( true ) ) ;
471
472
await waitFor ( ( ) => expect ( result . current . isFetching ) . toBe ( false ) ) ;
472
473
473
- // Should only be called once since chunking is explicitly disabled
474
+ // Should only be called once since chunking is disabled without timestampValueExpression
474
475
expect ( mockClickhouseClient . queryChartConfig ) . toHaveBeenCalledTimes ( 1 ) ;
475
476
expect ( mockClickhouseClient . queryChartConfig ) . toHaveBeenCalledWith ( {
476
477
config,
@@ -529,9 +530,12 @@ describe('useChartConfig', () => {
529
530
. mockResolvedValueOnce ( mockResponse2 )
530
531
. mockResolvedValueOnce ( mockResponse3 ) ;
531
532
532
- const { result } = renderHook ( ( ) => useQueriedChartConfig ( config ) , {
533
- wrapper,
534
- } ) ;
533
+ const { result } = renderHook (
534
+ ( ) => useChunkedQueriedChartConfig ( config ) ,
535
+ {
536
+ wrapper,
537
+ } ,
538
+ ) ;
535
539
536
540
await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBe ( true ) ) ;
537
541
await waitFor ( ( ) => expect ( result . current . isFetching ) . toBe ( false ) ) ;
@@ -620,9 +624,12 @@ describe('useChartConfig', () => {
620
624
. mockResolvedValueOnce ( mockResponse2 )
621
625
. mockResolvedValueOnce ( mockResponse3 ) ;
622
626
623
- const { result } = renderHook ( ( ) => useQueriedChartConfig ( config ) , {
624
- wrapper,
625
- } ) ;
627
+ const { result } = renderHook (
628
+ ( ) => useChunkedQueriedChartConfig ( config ) ,
629
+ {
630
+ wrapper,
631
+ } ,
632
+ ) ;
626
633
627
634
await waitFor ( ( ) => expect ( result . current . isSuccess ) . toBe ( true ) ) ;
628
635
await waitFor ( ( ) => expect ( result . current . isPending ) . toBe ( false ) ) ;
@@ -678,9 +685,12 @@ describe('useChartConfig', () => {
678
685
mockResponse1Promise ,
679
686
) ;
680
687
681
- const { result } = renderHook ( ( ) => useQueriedChartConfig ( config ) , {
682
- wrapper,
683
- } ) ;
688
+ const { result } = renderHook (
689
+ ( ) => useChunkedQueriedChartConfig ( config ) ,
690
+ {
691
+ wrapper,
692
+ } ,
693
+ ) ;
684
694
685
695
// Should be in loading state before first chunk
686
696
expect ( result . current . isLoading ) . toBe ( true ) ;
@@ -721,7 +731,11 @@ describe('useChartConfig', () => {
721
731
} ) ;
722
732
723
733
const { result } = renderHook (
724
- ( ) => useQueriedChartConfig ( config , { onError, retry : false } ) ,
734
+ ( ) =>
735
+ useChunkedQueriedChartConfig ( config , {
736
+ onError,
737
+ retry : false ,
738
+ } ) ,
725
739
{
726
740
wrapper,
727
741
} ,
@@ -752,7 +766,10 @@ describe('useChartConfig', () => {
752
766
mockClickhouseClient . queryChartConfig . mockResolvedValue ( mockResponse ) ;
753
767
754
768
const { result } = renderHook (
755
- ( ) => useQueriedChartConfig ( config , { enabled : false } ) ,
769
+ ( ) =>
770
+ useChunkedQueriedChartConfig ( config , {
771
+ enabled : false ,
772
+ } ) ,
756
773
{
757
774
wrapper,
758
775
} ,
0 commit comments