geido commented on code in PR #37229: URL: https://github.com/apache/superset/pull/37229#discussion_r2709212661
########## superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.test.ts: ########## @@ -0,0 +1,295 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { DatasourceType } from '@superset-ui/core'; +import transformProps from './transformProps'; +import { EchartsTimeseriesChartProps } from '../types'; +import { EchartsMixedTimeseriesProps } from './types'; + +const mockedProps = { + // Datasource metadata + datasource: { + id: 1, + name: 'test_datasource', + type: DatasourceType.Table, + columnFormats: {}, + currencyFormats: {}, + verboseMap: { + testing_count: 'Testing count', + 'SUM(money_for_learning)': 'SUM(money_for_learning)', + time_start: 'time_start', + }, + }, + + // Query results + queriesData: [ + { + label_map: { + time_start: ['time_start'], + 'SUM(money_for_learning)': ['SUM(money_for_learning)'], + 'SUM(money_for_learning), 1 day ago': [ + 'SUM(money_for_learning)', + '1 day ago', + ], + 'SUM(money_for_learning), 1 week ago': [ + 'SUM(money_for_learning)', + '1 week ago', + ], + 'SUM(money_for_learning), 1 year ago': [ + 'SUM(money_for_learning)', + '1 year ago', + ], + testing_count: ['testing_count'], + 'testing_count, 1 day ago': ['testing_count', '1 day ago'], + 'testing_count, 1 week ago': ['testing_count', '1 week ago'], + 'testing_count, 1 year ago': ['testing_count', '1 year ago'], + 'Testing count': ['testing_count'], + }, + colnames: [ + 'time_start', + 'SUM(money_for_learning)', + 'SUM(money_for_learning), 1 day ago', + 'SUM(money_for_learning), 1 week ago', + 'SUM(money_for_learning), 1 year ago', + 'testing_count', + 'testing_count, 1 day ago', + 'testing_count, 1 week ago', + 'testing_count, 1 year ago', + ], + indexnames: [0, 1, 2], + coltypes: [2, 0, 0, 0, 1, 0, 0, 0, 1], + data: [ + { + time_start: 1533081600001, + 'SUM(money_for_learning)': 101, + 'SUM(money_for_learning), 1 day ago': null, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 1, + 'testing_count, 1 day ago': null, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + { + time_start: 1533168000001, + 'SUM(money_for_learning)': 5791, + 'SUM(money_for_learning), 1 day ago': 101, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 131, + 'testing_count, 1 day ago': 11, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + ], + result_format: 'json', + applied_filters: [ + { + column: 'time_start', + }, + ], + rejected_filters: [], + }, + { + label_map: { + time_start: ['time_start'], + 'SUM(money_for_learning)': ['SUM(money_for_learning)'], + 'SUM(money_for_learning), 1 day ago': [ + 'SUM(money_for_learning)', + '1 day ago', + ], + 'SUM(money_for_learning), 1 week ago': [ + 'SUM(money_for_learning)', + '1 week ago', + ], + 'SUM(money_for_learning), 1 year ago': [ + 'SUM(money_for_learning)', + '1 year ago', + ], + testing_count: ['testing_count'], + 'testing_count, 1 day ago': ['testing_count', '1 day ago'], + 'testing_count, 1 week ago': ['testing_count', '1 week ago'], + 'testing_count, 1 year ago': ['testing_count', '1 year ago'], + 'Testing count': ['testing_count'], + }, + colnames: [ + 'time_start', + 'SUM(money_for_learning)', + 'SUM(money_for_learning), 1 day ago', + 'SUM(money_for_learning), 1 week ago', + 'SUM(money_for_learning), 1 year ago', + 'testing_count', + 'testing_count, 1 day ago', + 'testing_count, 1 week ago', + 'testing_count, 1 year ago', + ], + indexnames: [0, 1, 2], + coltypes: [2, 0, 0, 0, 1, 0, 0, 0, 1], + data: [ + { + time_start: 1533081600000, + 'SUM(money_for_learning)': 100, + 'SUM(money_for_learning), 1 day ago': null, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 1, + 'testing_count, 1 day ago': null, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + { + time_start: 1533168000000, + 'SUM(money_for_learning)': 5790, + 'SUM(money_for_learning), 1 day ago': 100, + 'SUM(money_for_learning), 1 week ago': null, + 'SUM(money_for_learning), 1 year ago': null, + testing_count: 13, + 'testing_count, 1 day ago': 1, + 'testing_count, 1 week ago': null, + 'testing_count, 1 year ago': null, + }, + ], + result_format: 'json', + applied_filters: [ + { + column: 'time_start', + }, + ], + rejected_filters: [], + }, + ] as unknown as EchartsTimeseriesChartProps['queriesData'], + + // Filter and legend state + filterState: { + selectedValues: [], + }, + legendState: {}, + + // Form data (chart configuration) + formData: { + metrics: [ + { + aggregate: 'SUM', + column: { + column_name: 'money_for_learning', + filterable: true, + groupby: true, + id: 460, + is_dttm: false, + type: 'DOUBLE PRECISION', + type_generic: 0, + }, + expressionType: 'SIMPLE', + hasCustomLabel: false, + label: 'SUM(money_for_learning)', + optionName: 'metric_olnflt1ak9g_z1vjg3dhmnf', + }, + 'testing_count', + ], + metricsB: [ + { + aggregate: 'SUM', + column: { + column_name: 'money_for_learning', + filterable: true, + groupby: true, + id: 460, + is_dttm: false, + type: 'DOUBLE PRECISION', + type_generic: 0, + }, + expressionType: 'SIMPLE', + hasCustomLabel: false, + label: 'SUM(money_for_learning)', + optionName: 'metric_olnflt1ak9g_z1vjg3dhmnf', + }, + 'testing_count', + ], + } as unknown as EchartsTimeseriesChartProps['formData'], + + // Hooks + hooks: { + setDataMask: () => {}, + setControlValue: () => {}, + onContextMenu: () => {}, + onLegendStateChanged: () => {}, + onLegendScroll: () => {}, + }, + + // UI state + inContextMenu: false, + emitCrossFilters: true, + legendIndex: 0, + + // Raw form data (needed for additional validation) + rawFormData: { + datasource: '1__table', + viz_type: 'echarts_timeseries', + x_axis: 'ds', + time_compare: [], + } as unknown as EchartsTimeseriesChartProps['rawFormData'], + + // Theme + theme: {}, +} as unknown as EchartsMixedTimeseriesProps; Review Comment: Do we need these `unknown`. Should we centralize the mocks? Probably out of scope for the work but something worth considering -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
