@@ -6,7 +6,7 @@ import { waitFor } from "@testing-library/react";
66import highcharts from "highcharts" ;
77import { vi } from "vitest" ;
88
9- import { CoreChartAPI } from "../../../lib/components/core/interfaces" ;
9+ import { CoreChartProps } from "../../../lib/components/core/interfaces" ;
1010import testClasses from "../../../lib/components/core/test-classes/styles.selectors" ;
1111import { createChartWrapper , renderChart } from "./common" ;
1212import { HighchartsTestHelper } from "./highcharts-utils" ;
@@ -51,7 +51,7 @@ const data = [
5151 { name : "P3" , y : 60 } ,
5252] ;
5353
54- const series : Highcharts . SeriesOptionsType [ ] = [
54+ const pieSeries : Highcharts . SeriesOptionsType [ ] = [
5555 {
5656 type : "pie" ,
5757 name : "Pie series" ,
@@ -84,7 +84,7 @@ describe("CoreChart: tooltip", () => {
8484 test ( "renders highcharts tooltip" , ( ) => {
8585 const { wrapper } = renderChart ( {
8686 highcharts,
87- options : { series, tooltip : { enabled : true , formatter : ( ) => "Custom content" } } ,
87+ options : { series : pieSeries , tooltip : { enabled : true , formatter : ( ) => "Custom content" } } ,
8888 tooltip : { enabled : false } ,
8989 } ) ;
9090
@@ -184,12 +184,12 @@ describe("CoreChart: tooltip", () => {
184184 } ) ;
185185
186186 test ( "shows tooltip with api" , async ( ) => {
187- let api : null | CoreChartAPI = null ;
187+ let api : null | CoreChartProps . ChartAPI = null ;
188188 const onHighlight = vi . fn ( ) ;
189189 const onClearHighlight = vi . fn ( ) ;
190190 const { wrapper } = renderChart ( {
191191 highcharts,
192- options : { series } ,
192+ options : { series : pieSeries } ,
193193 onHighlight,
194194 onClearHighlight,
195195 getTooltipContent : ( ) => ( {
@@ -221,7 +221,7 @@ describe("CoreChart: tooltip", () => {
221221 test ( "keeps showing tooltip when cursor is over the tooltip" , async ( ) => {
222222 const { wrapper } = renderChart ( {
223223 highcharts,
224- options : { series } ,
224+ options : { series : pieSeries } ,
225225 getTooltipContent : ( ) => ( { header : ( ) => "" , body : ( ) => "" } ) ,
226226 } ) ;
227227
@@ -250,7 +250,7 @@ describe("CoreChart: tooltip", () => {
250250 test ( "pins and unpins tooltip" , async ( ) => {
251251 const { wrapper } = renderChart ( {
252252 highcharts,
253- options : { series } ,
253+ options : { series : pieSeries } ,
254254 getTooltipContent : ( { point } ) => ( { header : ( ) => `y${ point ?. y } ` , body : ( ) => "" } ) ,
255255 } ) ;
256256
@@ -291,7 +291,7 @@ describe("CoreChart: tooltip", () => {
291291 test ( "provides point and group for onHighlight and getTooltipContent" , async ( ) => {
292292 const onHighlight = vi . fn ( ) ;
293293 const getTooltipContent = vi . fn ( ) ;
294- renderChart ( { highcharts, options : { series } , onHighlight, getTooltipContent } ) ;
294+ renderChart ( { highcharts, options : { series : pieSeries } , onHighlight, getTooltipContent } ) ;
295295
296296 for ( let i = 0 ; i < data . length ; i ++ ) {
297297 act ( ( ) => hc . highlightChartPoint ( 0 , i ) ) ;
@@ -370,4 +370,39 @@ describe("CoreChart: tooltip", () => {
370370 expect ( onHighlight ) . toHaveBeenCalledWith ( expect . objectContaining ( { point : hc . getChartPoint ( 0 , 1 ) } ) ) ;
371371 } ,
372372 ) ;
373+
374+ test ( "renders customized cartesian points" , ( ) => {
375+ const { wrapper } = renderChart ( {
376+ highcharts,
377+ options : { series : lineSeries } ,
378+ getTooltipContent : ( ) => ( {
379+ header : ( ) => "Header" ,
380+ point : ( { item } ) => ( { key : ` [${ item . point . series . name } ]` , value : ` [${ item . point . y } ]` } ) ,
381+ } ) ,
382+ } ) ;
383+
384+ act ( ( ) => hc . highlightChartPoint ( 0 , 2 ) ) ;
385+
386+ expect ( wrapper . findTooltip ( ) ! . findBody ( ) ! . getElement ( ) . textContent ) . toBe (
387+ " [Line series 1] [13] [Line series 2] [23]" ,
388+ ) ;
389+ } ) ;
390+
391+ test ( "renders customized pie segment details" , ( ) => {
392+ const { wrapper } = renderChart ( {
393+ highcharts,
394+ options : { series : pieSeries } ,
395+ getTooltipContent : ( ) => ( {
396+ header : ( ) => "Header" ,
397+ details : ( { point } ) => [
398+ { key : `[${ point . name } ]` , value : ` [${ point . y } ]` } ,
399+ { key : " [custom key]" , value : " [custom value]" } ,
400+ ] ,
401+ } ) ,
402+ } ) ;
403+
404+ act ( ( ) => hc . highlightChartPoint ( 0 , 2 ) ) ;
405+
406+ expect ( wrapper . findTooltip ( ) ! . findBody ( ) ! . getElement ( ) . textContent ) . toBe ( "[P3] [60] [custom key] [custom value]" ) ;
407+ } ) ;
373408} ) ;
0 commit comments