@@ -26,7 +26,7 @@ vi.mock('chart.js', () => {
2626
2727vi . mock ( 'chartjs-plugin-zoom' , ( ) => ( { default : { } } ) ) ;
2828
29- import ChartContainer , { getComparisonData , getActiveElementsAtStep } from '../ChartContainer.jsx' ;
29+ import ChartContainer , { getComparisonData , getActiveElementsAtStep , syncHoverToCharts } from '../ChartContainer.jsx' ;
3030
3131const sampleFile = {
3232 name : 'test.log' ,
@@ -126,4 +126,33 @@ describe('ChartContainer', () => {
126126 const result = getActiveElementsAtStep ( datasets , 0 ) ;
127127 expect ( result ) . toEqual ( [ ] ) ;
128128 } ) ;
129+
130+ it ( 'clears highlights when step is absent' , ( ) => {
131+ const chart = {
132+ setActiveElements : vi . fn ( ) ,
133+ tooltip : { setActiveElements : vi . fn ( ) } ,
134+ update : vi . fn ( ) ,
135+ data : { datasets : [ { data : [ { x : 210 , y : 1 } ] } ] }
136+ } ;
137+ const charts = new Map ( [ [ "a" , chart ] ] ) ;
138+ syncHoverToCharts ( charts , 0 ) ;
139+ expect ( chart . setActiveElements ) . toHaveBeenCalledWith ( [ ] ) ;
140+ expect ( chart . tooltip . setActiveElements ) . toHaveBeenCalledWith ( [ ] ) ;
141+ expect ( chart . update ) . toHaveBeenCalledWith ( 'none' ) ;
142+ } ) ;
143+
144+ it ( 'positions tooltip at matching step' , ( ) => {
145+ const chart = {
146+ setActiveElements : vi . fn ( ) ,
147+ tooltip : { setActiveElements : vi . fn ( ) } ,
148+ update : vi . fn ( ) ,
149+ data : { datasets : [ { data : [ { x : 210 , y : 1 } ] } ] } ,
150+ scales : { x : { getPixelForValue : vi . fn ( ) . mockReturnValue ( 123 ) } }
151+ } ;
152+ const charts = new Map ( [ [ "a" , chart ] ] ) ;
153+ syncHoverToCharts ( charts , 210 ) ;
154+ expect ( chart . setActiveElements ) . toHaveBeenCalledWith ( [ { datasetIndex : 0 , index : 0 } ] ) ;
155+ expect ( chart . tooltip . setActiveElements ) . toHaveBeenCalledWith ( [ { datasetIndex : 0 , index : 0 } ] , { x : 123 , y : 0 } ) ;
156+ expect ( chart . update ) . toHaveBeenCalledWith ( 'none' ) ;
157+ } ) ;
129158 } ) ;
0 commit comments