1717 * under the License.
1818 */
1919
20- import { ChartProps , SMART_DATE_ID , supersetTheme } from '@superset-ui/core' ;
20+ import { ChartProps , SMART_DATE_ID } from '@superset-ui/core' ;
2121import transformProps from '../../../src/Timeseries/transformProps' ;
2222import { DEFAULT_FORM_DATA } from '../../../src/Timeseries/constants' ;
2323import {
@@ -30,6 +30,7 @@ import {
3030 D3_FORMAT_OPTIONS ,
3131 D3_TIME_FORMAT_OPTIONS ,
3232} from '@superset-ui/chart-controls' ;
33+ import { supersetTheme } from '@apache-superset/core/ui' ;
3334
3435describe ( 'Scatter Chart X-axis Time Formatting' , ( ) => {
3536 const baseFormData : EchartsTimeseriesFormData = {
@@ -69,6 +70,7 @@ describe('Scatter Chart X-axis Time Formatting', () => {
6970 } ) ;
7071
7172 const transformedProps = transformProps (
73+ // @ts -ignore
7274 chartProps as EchartsTimeseriesChartProps ,
7375 ) ;
7476
@@ -78,28 +80,32 @@ describe('Scatter Chart X-axis Time Formatting', () => {
7880 expect ( xAxis . axisLabel . formatter ) . toBeUndefined ( ) ;
7981 } ) ;
8082
81- test . each ( D3_TIME_FORMAT_OPTIONS ) ( 'should handle %s format' , format => {
82- const chartProps = new ChartProps ( {
83- ...baseChartPropsConfig ,
84- formData : {
85- ...baseFormData ,
86- xAxisTimeFormat : format ,
87- } ,
88- } ) ;
89-
90- const transformedProps = transformProps (
91- chartProps as EchartsTimeseriesChartProps ,
92- ) ;
93-
94- const xAxis = transformedProps . echartOptions . xAxis as any ;
95- expect ( xAxis . axisLabel ) . toHaveProperty ( 'formatter' ) ;
96- if ( format === SMART_DATE_ID ) {
97- expect ( xAxis . axisLabel . formatter ) . toBeUndefined ( ) ;
98- } else {
99- expect ( typeof xAxis . axisLabel . formatter ) . toBe ( 'function' ) ;
100- expect ( xAxis . axisLabel . formatter . id ) . toBe ( format ) ;
101- }
102- } ) ;
83+ test . each ( D3_TIME_FORMAT_OPTIONS . map ( ( [ id ] ) => id ) ) (
84+ 'should handle %s format' ,
85+ format => {
86+ const chartProps = new ChartProps ( {
87+ ...baseChartPropsConfig ,
88+ formData : {
89+ ...baseFormData ,
90+ xAxisTimeFormat : format ,
91+ } ,
92+ } ) ;
93+
94+ const transformedProps = transformProps (
95+ // @ts -ignore
96+ chartProps as EchartsTimeseriesChartProps ,
97+ ) ;
98+
99+ const xAxis = transformedProps . echartOptions . xAxis as any ;
100+ expect ( xAxis . axisLabel ) . toHaveProperty ( 'formatter' ) ;
101+ if ( format === SMART_DATE_ID ) {
102+ expect ( xAxis . axisLabel . formatter ) . toBeUndefined ( ) ;
103+ } else {
104+ expect ( typeof xAxis . axisLabel . formatter ) . toBe ( 'function' ) ;
105+ expect ( xAxis . axisLabel . formatter . id ) . toBe ( format ) ;
106+ }
107+ } ,
108+ ) ;
103109} ) ;
104110
105111describe ( 'Scatter Chart X-axis Number Formatting' , ( ) => {
@@ -140,6 +146,7 @@ describe('Scatter Chart X-axis Number Formatting', () => {
140146 } ) ;
141147
142148 const transformedProps = transformProps (
149+ // @ts -ignore
143150 chartProps as EchartsTimeseriesChartProps ,
144151 ) ;
145152
@@ -150,23 +157,27 @@ describe('Scatter Chart X-axis Number Formatting', () => {
150157 expect ( xAxis . axisLabel . formatter . id ) . toBe ( 'SMART_NUMBER' ) ;
151158 } ) ;
152159
153- test . each ( D3_FORMAT_OPTIONS ) ( 'should handle %s format' , format => {
154- const chartProps = new ChartProps ( {
155- ...baseChartPropsConfig ,
156- formData : {
157- ...baseFormData ,
158- xAxisNumberFormat : format ,
159- } ,
160- } ) ;
161-
162- const transformedProps = transformProps (
163- chartProps as EchartsTimeseriesChartProps ,
164- ) ;
165-
166- expect ( transformedProps . echartOptions . xAxis ) . toHaveProperty ( 'axisLabel' ) ;
167- const xAxis = transformedProps . echartOptions . xAxis as any ;
168- expect ( xAxis . axisLabel ) . toHaveProperty ( 'formatter' ) ;
169- expect ( typeof xAxis . axisLabel . formatter ) . toBe ( 'function' ) ;
170- expect ( xAxis . axisLabel . formatter . id ) . toBe ( format ) ;
171- } ) ;
160+ test . each ( D3_FORMAT_OPTIONS . map ( ( [ id ] ) => id ) ) (
161+ 'should handle %s format' ,
162+ format => {
163+ const chartProps = new ChartProps ( {
164+ ...baseChartPropsConfig ,
165+ formData : {
166+ ...baseFormData ,
167+ xAxisNumberFormat : format ,
168+ } ,
169+ } ) ;
170+
171+ const transformedProps = transformProps (
172+ // @ts -ignore
173+ chartProps as EchartsTimeseriesChartProps ,
174+ ) ;
175+
176+ expect ( transformedProps . echartOptions . xAxis ) . toHaveProperty ( 'axisLabel' ) ;
177+ const xAxis = transformedProps . echartOptions . xAxis as any ;
178+ expect ( xAxis . axisLabel ) . toHaveProperty ( 'formatter' ) ;
179+ expect ( typeof xAxis . axisLabel . formatter ) . toBe ( 'function' ) ;
180+ expect ( xAxis . axisLabel . formatter . id ) . toBe ( format ) ;
181+ } ,
182+ ) ;
172183} ) ;
0 commit comments