1+ jest . mock ( "@mendix/shared-charts/main" , ( ) => {
2+ const actualModule = jest . requireActual ( "@mendix/shared-charts/main" ) ;
3+ return {
4+ ...actualModule ,
5+ ChartWidget : jest . fn ( ( ) => null )
6+ } ;
7+ } ) ;
8+
19import { ChartWidget } from "@mendix/shared-charts/main" ;
2- import { list , listExp , EditableValueBuilder , ListAttributeValueBuilder } from "@mendix/widget-plugin-test-utils" ;
10+ import {
11+ EditableValueBuilder ,
12+ list ,
13+ ListAttributeValueBuilder ,
14+ listExpression
15+ } from "@mendix/widget-plugin-test-utils" ;
16+ import "@testing-library/jest-dom" ;
17+ import { render , RenderResult } from "@testing-library/react" ;
318import Big from "big.js" ;
4- import { mount , ReactWrapper } from "enzyme" ;
519import { createElement } from "react" ;
620import { SeriesType } from "../../typings/AreaChartProps" ;
721import { AreaChart } from "../AreaChart" ;
822
923jest . mock ( "react-plotly.js" , ( ) => jest . fn ( ( ) => null ) ) ;
1024
1125describe ( "The AreaChart widget" , ( ) => {
12- function renderAreaChart ( configs : Array < Partial < SeriesType > > ) : ReactWrapper {
13- return mount (
26+ function renderAreaChart ( configs : Array < Partial < SeriesType > > ) : RenderResult {
27+ return render (
1428 < AreaChart
1529 name = "line-chart-test"
1630 class = "line-chart-class"
@@ -31,77 +45,117 @@ describe("The AreaChart widget", () => {
3145 }
3246
3347 it ( "visualizes data as a area chart" , ( ) => {
34- const areaChart = renderAreaChart ( [ { } ] ) ;
35- const data = areaChart . find ( ChartWidget ) . prop ( "data" ) ;
36- expect ( data ) . toHaveLength ( 1 ) ;
37- expect ( data [ 0 ] ) . toHaveProperty ( "type" , "scatter" ) ;
38- expect ( data [ 0 ] ) . toHaveProperty ( "fill" , "tonexty" ) ;
48+ renderAreaChart ( [ { } ] ) ;
49+
50+ expect ( ChartWidget ) . toHaveBeenCalledWith (
51+ expect . objectContaining ( {
52+ data : expect . arrayContaining ( [
53+ expect . objectContaining ( {
54+ type : "scatter" ,
55+ fill : "tonexty"
56+ } )
57+ ] )
58+ } ) ,
59+ { }
60+ ) ;
3961 } ) ;
4062
4163 it ( "sets the mode on the data series based on the lineStyle value" , ( ) => {
42- const areaChart = renderAreaChart ( [ { lineStyle : "lineWithMarkers" } , { lineStyle : "line" } ] ) ;
43- const data = areaChart . find ( ChartWidget ) . prop ( "data" ) ;
44- expect ( data ) . toHaveLength ( 2 ) ;
45- expect ( data [ 0 ] ) . toHaveProperty ( "mode" , "lines+markers" ) ;
46- expect ( data [ 1 ] ) . toHaveProperty ( "mode" , "lines" ) ;
64+ renderAreaChart ( [ { lineStyle : "lineWithMarkers" } , { lineStyle : "line" } ] ) ;
65+
66+ expect ( ChartWidget ) . toHaveBeenCalledWith (
67+ expect . objectContaining ( {
68+ data : expect . arrayContaining ( [
69+ expect . objectContaining ( { mode : "lines+markers" } ) ,
70+ expect . objectContaining ( { mode : "lines" } )
71+ ] )
72+ } ) ,
73+ { }
74+ ) ;
4775 } ) ;
4876
4977 it ( "sets the line shape on the data series based on the interpolation value" , ( ) => {
50- const areaChart = renderAreaChart ( [ { interpolation : "linear" } , { interpolation : "spline" } ] ) ;
51- const data = areaChart . find ( ChartWidget ) . prop ( "data" ) ;
52- expect ( data ) . toHaveLength ( 2 ) ;
53- expect ( data [ 0 ] ) . toHaveProperty ( "line.shape" , "linear" ) ;
54- expect ( data [ 1 ] ) . toHaveProperty ( "line.shape" , "spline" ) ;
78+ renderAreaChart ( [ { interpolation : "linear" } , { interpolation : "spline" } ] ) ;
79+
80+ expect ( ChartWidget ) . toHaveBeenCalledWith (
81+ expect . objectContaining ( {
82+ data : expect . arrayContaining ( [
83+ expect . objectContaining ( { line : expect . objectContaining ( { shape : "linear" } ) } ) ,
84+ expect . objectContaining ( { line : expect . objectContaining ( { shape : "spline" } ) } )
85+ ] )
86+ } ) ,
87+ { }
88+ ) ;
5589 } ) ;
5690
5791 it ( "sets the line color on the data series based on the lineColor value" , ( ) => {
58- const areaChart = renderAreaChart ( [ { staticLineColor : listExp ( ( ) => "red" ) } , { staticLineColor : undefined } ] ) ;
59- const data = areaChart . find ( ChartWidget ) . prop ( "data" ) ;
60- expect ( data ) . toHaveLength ( 2 ) ;
61- expect ( data [ 0 ] ) . toHaveProperty ( "line.color" , "red" ) ;
62- expect ( data [ 1 ] ) . toHaveProperty ( "line.color" , undefined ) ;
92+ renderAreaChart ( [ { staticLineColor : listExpression ( ( ) => "red" ) } , { staticLineColor : undefined } ] ) ;
93+
94+ expect ( ChartWidget ) . toHaveBeenCalledWith (
95+ expect . objectContaining ( {
96+ data : expect . arrayContaining ( [
97+ expect . objectContaining ( { line : expect . objectContaining ( { color : "red" } ) } ) ,
98+ expect . objectContaining ( { line : expect . objectContaining ( { color : undefined } ) } )
99+ ] )
100+ } ) ,
101+ { }
102+ ) ;
63103 } ) ;
64104
65105 it ( "sets the marker color on the data series based on the markerColor value" , ( ) => {
66- const areaChart = renderAreaChart ( [
67- { staticMarkerColor : undefined } ,
68- { staticMarkerColor : listExp ( ( ) => "blue" ) }
69- ] ) ;
70- const data = areaChart . find ( ChartWidget ) . prop ( "data" ) ;
71- expect ( data ) . toHaveLength ( 2 ) ;
72- expect ( data [ 0 ] ) . toHaveProperty ( "marker.color" , undefined ) ;
73- expect ( data [ 1 ] ) . toHaveProperty ( "marker.color" , "blue" ) ;
106+ renderAreaChart ( [ { staticMarkerColor : undefined } , { staticMarkerColor : listExpression ( ( ) => "blue" ) } ] ) ;
107+
108+ expect ( ChartWidget ) . toHaveBeenCalledWith (
109+ expect . objectContaining ( {
110+ data : expect . arrayContaining ( [
111+ expect . objectContaining ( { marker : expect . objectContaining ( { color : undefined } ) } ) ,
112+ expect . objectContaining ( { marker : expect . objectContaining ( { color : "blue" } ) } )
113+ ] )
114+ } ) ,
115+ { }
116+ ) ;
74117 } ) ;
75118
76119 it ( "sets the area color on the data series based on the fillcolor value" , ( ) => {
77- const areaChart = renderAreaChart ( [
78- { staticFillColor : undefined } ,
79- { staticFillColor : listExp ( ( ) => "#393393" ) }
80- ] ) ;
81- const data = areaChart . find ( ChartWidget ) . prop ( "data" ) ;
82- expect ( data ) . toHaveLength ( 2 ) ;
83- expect ( data [ 0 ] ) . toHaveProperty ( "fillcolor" , undefined ) ;
84- expect ( data [ 1 ] ) . toHaveProperty ( "fillcolor" , "#393393" ) ;
120+ renderAreaChart ( [ { staticFillColor : undefined } , { staticFillColor : listExpression ( ( ) => "#393393" ) } ] ) ;
121+
122+ expect ( ChartWidget ) . toHaveBeenCalledWith (
123+ expect . objectContaining ( {
124+ data : expect . arrayContaining ( [
125+ expect . objectContaining ( { fillcolor : undefined } ) ,
126+ expect . objectContaining ( { fillcolor : "#393393" } )
127+ ] )
128+ } ) ,
129+ { }
130+ ) ;
85131 } ) ;
86132
87133 it ( "sets the appropriate transforms on the data series based on the aggregation type" , ( ) => {
88- const areaChart = renderAreaChart ( [ { aggregationType : "none" } , { aggregationType : "avg" } ] ) ;
89- const data = areaChart . find ( ChartWidget ) . prop ( "data" ) ;
90- expect ( data ) . toHaveLength ( 2 ) ;
91- expect ( data [ 0 ] ) . toHaveProperty ( "transforms" , [ ] ) ;
92- expect ( data [ 1 ] ) . toHaveProperty ( "transforms" , [
93- {
94- type : "aggregate" ,
95- groups : [ "1" , "2" ] ,
96- aggregations : [
97- {
98- target : "y" ,
99- enabled : true ,
100- func : "avg"
101- }
102- ]
103- }
104- ] ) ;
134+ renderAreaChart ( [ { aggregationType : "none" } , { aggregationType : "avg" } ] ) ;
135+
136+ expect ( ChartWidget ) . toHaveBeenCalledWith (
137+ expect . objectContaining ( {
138+ data : expect . arrayContaining ( [
139+ expect . objectContaining ( { transforms : [ ] } ) ,
140+ expect . objectContaining ( {
141+ transforms : [
142+ {
143+ type : "aggregate" ,
144+ groups : [ "1" , "2" ] ,
145+ aggregations : [
146+ {
147+ target : "y" ,
148+ enabled : true ,
149+ func : "avg"
150+ }
151+ ]
152+ }
153+ ]
154+ } )
155+ ] )
156+ } ) ,
157+ { }
158+ ) ;
105159 } ) ;
106160} ) ;
107161
0 commit comments