1- import { ChartWidget } from "@mendix/shared-charts/main" ;
2- import { EditableValueBuilder , ListAttributeValueBuilder , list , listExp } from "@mendix/widget-plugin-test-utils" ;
3- import Big from "big.js" ;
1+ import { ChartWidget , setupBasicSeries } from "@mendix/shared-charts/main" ;
2+ import { listExpression } from "@mendix/widget-plugin-test-utils" ;
43import { render , RenderResult } from "@testing-library/react" ;
54import { createElement } from "react" ;
65import { ColumnChartContainerProps , SeriesType } from "../../typings/ColumnChartProps" ;
@@ -26,7 +25,7 @@ describe("The ColumnChart widget", () => {
2625 name = "column-chart-test"
2726 class = "column-chart-class"
2827 barmode = "group"
29- series = { configs . map ( setupBasicSeries ) }
28+ series = { configs . map ( setupBasicColumnSeries ) }
3029 showLegend = { false }
3130 widthUnit = "percentage"
3231 width = { 0 }
@@ -58,7 +57,7 @@ describe("The ColumnChart widget", () => {
5857 } ) ;
5958
6059 it ( "sets the bar color on the data series based on the barColor value" , ( ) => {
61- renderColumnChart ( [ { staticBarColor : listExp ( ( ) => "red" ) } , { staticBarColor : undefined } ] ) ;
60+ renderColumnChart ( [ { staticBarColor : listExpression ( ( ) => "red" ) } , { staticBarColor : undefined } ] ) ;
6261
6362 const mockCalls = ( ChartWidget as jest . Mock ) . mock . calls ;
6463 const lastCallProps = mockCalls [ mockCalls . length - 1 ] [ 0 ] ;
@@ -105,26 +104,11 @@ describe("The ColumnChart widget", () => {
105104 } ) ;
106105} ) ;
107106
108- function setupBasicSeries ( overwriteConfig : Partial < SeriesType > ) : SeriesType {
109- const xAttribute = new ListAttributeValueBuilder < Big > ( ) . build ( ) ;
110- const getXAttributeMock = jest . fn ( ) ;
111- getXAttributeMock . mockReturnValueOnce ( new EditableValueBuilder < Big > ( ) . withValue ( new Big ( 1 ) ) . build ( ) ) ;
112- getXAttributeMock . mockReturnValueOnce ( new EditableValueBuilder < Big > ( ) . withValue ( new Big ( 2 ) ) . build ( ) ) ;
113- xAttribute . get = getXAttributeMock ;
114-
115- const yAttribute = new ListAttributeValueBuilder < Big > ( ) . build ( ) ;
116- const getYAttributeMock = jest . fn ( ) ;
117- getYAttributeMock . mockReturnValueOnce ( new EditableValueBuilder < Big > ( ) . withValue ( new Big ( 3 ) ) . build ( ) ) ;
118- getYAttributeMock . mockReturnValueOnce ( new EditableValueBuilder < Big > ( ) . withValue ( new Big ( 6 ) ) . build ( ) ) ;
119- yAttribute . get = getYAttributeMock ;
107+ function setupBasicColumnSeries ( overwriteConfig : Partial < SeriesType > ) : SeriesType {
108+ const basicSeries = setupBasicSeries ( overwriteConfig ) as SeriesType ;
120109
121110 return {
122- dataSet : "static" ,
123- customSeriesOptions : overwriteConfig . customSeriesOptions ?? "" ,
124- aggregationType : overwriteConfig . aggregationType ?? "avg" ,
125- staticBarColor : overwriteConfig . staticBarColor ?? undefined ,
126- staticDataSource : list ( 2 ) ,
127- staticXAttribute : xAttribute ,
128- staticYAttribute : yAttribute
111+ ...basicSeries ,
112+ staticBarColor : overwriteConfig . staticBarColor ?? undefined
129113 } ;
130114}
0 commit comments