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" ;
4
3
import { render , RenderResult } from "@testing-library/react" ;
5
4
import { createElement } from "react" ;
6
5
import { ColumnChartContainerProps , SeriesType } from "../../typings/ColumnChartProps" ;
@@ -26,7 +25,7 @@ describe("The ColumnChart widget", () => {
26
25
name = "column-chart-test"
27
26
class = "column-chart-class"
28
27
barmode = "group"
29
- series = { configs . map ( setupBasicSeries ) }
28
+ series = { configs . map ( setupBasicColumnSeries ) }
30
29
showLegend = { false }
31
30
widthUnit = "percentage"
32
31
width = { 0 }
@@ -58,7 +57,7 @@ describe("The ColumnChart widget", () => {
58
57
} ) ;
59
58
60
59
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 } ] ) ;
62
61
63
62
const mockCalls = ( ChartWidget as jest . Mock ) . mock . calls ;
64
63
const lastCallProps = mockCalls [ mockCalls . length - 1 ] [ 0 ] ;
@@ -105,26 +104,11 @@ describe("The ColumnChart widget", () => {
105
104
} ) ;
106
105
} ) ;
107
106
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 ;
120
109
121
110
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
129
113
} ;
130
114
}
0 commit comments