@@ -5,7 +5,7 @@ import { act } from "react";
55import highcharts from "highcharts" ;
66import { vi } from "vitest" ;
77
8- import { CoreChartAPI } from "../../../lib/components/core/interfaces" ;
8+ import { CoreChartProps } from "../../../lib/components/core/interfaces" ;
99import { renderChart , selectLegendItem } from "./common" ;
1010import { HighchartsTestHelper } from "./highcharts-utils" ;
1111
@@ -18,10 +18,28 @@ const series: Highcharts.SeriesOptionsType[] = [
1818 { type : "line" , name : "Line 2" , data : [ 4 , 5 , 6 ] } ,
1919] ;
2020
21+ const threeSeries : Highcharts . SeriesOptionsType [ ] = [
22+ { type : "line" , name : "Line 1" , data : [ 1 , 2 , 3 ] } ,
23+ { type : "line" , name : "Line 2" , data : [ 4 , 5 , 6 ] } ,
24+ { type : "line" , name : "Line 3" , data : [ 7 , 8 , 9 ] } ,
25+ ] ;
26+
27+ const pieSeries : Highcharts . SeriesOptionsType [ ] = [
28+ {
29+ type : "pie" ,
30+ name : "Data" ,
31+ data : [
32+ { name : "Segment 1" , y : 33.3 } ,
33+ { name : "Segment 2" , y : 33.3 } ,
34+ { name : "Segment 3" , y : 33.4 } ,
35+ ] ,
36+ } ,
37+ ] ;
38+
2139describe ( "CoreChart: API tests" , ( ) => {
2240 test ( "passes isApiCall=false to onHighlight when triggered by an user interaction" , ( ) => {
2341 const onHighlight = vi . fn ( ) ;
24- renderChart ( { highcharts, options : { series } , onHighlight } ) ;
42+ renderChart ( { highcharts, onHighlight , options : { series } } ) ;
2543
2644 act ( ( ) => hc . highlightChartPoint ( 0 , 0 ) ) ;
2745
@@ -32,7 +50,7 @@ describe("CoreChart: API tests", () => {
3250
3351 test ( "passes isApiCall=true to onHighlight when triggered programmatically through API" , ( ) => {
3452 const onHighlight = vi . fn ( ) ;
35- let chartApi : CoreChartAPI | null = null ;
53+ let chartApi : CoreChartProps . ChartAPI | null = null ;
3654
3755 renderChart ( { highcharts, onHighlight, options : { series } , callback : ( api ) => ( chartApi = api ) } ) ;
3856
@@ -55,7 +73,7 @@ describe("CoreChart: API tests", () => {
5573
5674 test ( "passes isApiCall=true to onClearHighlight when triggered programmatically through API" , ( ) => {
5775 const onClearHighlight = vi . fn ( ) ;
58- let chartApi : CoreChartAPI | null = null ;
76+ let chartApi : CoreChartProps . ChartAPI | null = null ;
5977
6078 renderChart ( { highcharts, onClearHighlight, options : { series } , callback : ( api ) => ( chartApi = api ) } ) ;
6179
@@ -74,11 +92,49 @@ describe("CoreChart: API tests", () => {
7492
7593 test ( "passes isApiCall=true to onVisibleItemsChange when triggered programmatically through API" , ( ) => {
7694 const onVisibleItemsChange = vi . fn ( ) ;
77- let chartApi : CoreChartAPI | null = null ;
95+ let chartApi : CoreChartProps . ChartAPI | null = null ;
7896
7997 renderChart ( { highcharts, options : { series } , onVisibleItemsChange, callback : ( api ) => ( chartApi = api ) } ) ;
8098
8199 act ( ( ) => chartApi ! . setItemsVisible ( [ "Line 1" ] ) ) ;
82100 expect ( onVisibleItemsChange ) . toHaveBeenCalledWith ( { items : expect . any ( Array ) , isApiCall : true } ) ;
83101 } ) ;
102+
103+ test ( "highlightItems should only highlight the specified series in a line chart" , ( ) => {
104+ let chartApi : CoreChartProps . ChartAPI | null = null ;
105+ renderChart ( { highcharts, options : { series : threeSeries } , callback : ( api ) => ( chartApi = api ) } ) ;
106+
107+ act ( ( ) => chartApi ! . highlightItems ( [ hc . getChartSeries ( 1 ) . name ] ) ) ;
108+
109+ expect ( hc . getChartSeries ( 0 ) . state ) . toBe ( "inactive" ) ;
110+ expect ( hc . getChartSeries ( 1 ) . state ) . toBe ( "" ) ;
111+ expect ( hc . getChartSeries ( 2 ) . state ) . toBe ( "inactive" ) ;
112+
113+ act ( ( ) => chartApi ! . clearChartHighlight ( ) ) ;
114+ act ( ( ) => chartApi ! . highlightItems ( [ hc . getChartSeries ( 0 ) . name , hc . getChartSeries ( 2 ) . name ] ) ) ;
115+
116+ expect ( hc . getChartSeries ( 0 ) . state ) . toBe ( "" ) ;
117+ expect ( hc . getChartSeries ( 1 ) . state ) . toBe ( "inactive" ) ;
118+ expect ( hc . getChartSeries ( 2 ) . state ) . toBe ( "" ) ;
119+ } ) ;
120+
121+ test ( "highlightItems should only highlight the specified point in a pie chart" , ( ) => {
122+ let chartApi : CoreChartProps . ChartAPI | null = null ;
123+ renderChart ( { highcharts, options : { series : pieSeries } , callback : ( api ) => ( chartApi = api ) } ) ;
124+
125+ const series = hc . getChartSeries ( 0 ) ;
126+
127+ act ( ( ) => chartApi ! . highlightItems ( [ series . points [ 1 ] . name ] ) ) ;
128+
129+ expect ( hc . getChartPoint ( 0 , 0 ) . state ) . toBe ( undefined ) ;
130+ expect ( hc . getChartPoint ( 0 , 1 ) . state ) . toBe ( "hover" ) ;
131+ expect ( hc . getChartPoint ( 0 , 2 ) . state ) . toBe ( undefined ) ;
132+
133+ act ( ( ) => chartApi ! . clearChartHighlight ( ) ) ;
134+ act ( ( ) => chartApi ! . highlightItems ( [ series . points [ 0 ] . name , series . points [ 2 ] . name ] ) ) ;
135+
136+ expect ( hc . getChartPoint ( 0 , 0 ) . state ) . toBe ( "hover" ) ;
137+ expect ( hc . getChartPoint ( 0 , 1 ) . state ) . toBe ( "" ) ;
138+ expect ( hc . getChartPoint ( 0 , 2 ) . state ) . toBe ( "hover" ) ;
139+ } ) ;
84140} ) ;
0 commit comments