zhaoyongjie commented on code in PR #20010:
URL: https://github.com/apache/superset/pull/20010#discussion_r873690776


##########
superset-frontend/src/explore/controlUtils/standardizedFormData.test.tsx:
##########
@@ -0,0 +1,267 @@
+/**
+ * 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 { getChartControlPanelRegistry, SqlaFormData } from '@superset-ui/core';
+import TableChartPlugin from '@superset-ui/plugin-chart-table';
+import { BigNumberTotalChartPlugin } from '@superset-ui/plugin-chart-echarts';
+import { sections } from '@superset-ui/chart-controls';
+import {
+  StandardizedFormData,
+  sharedControls,
+  publicControls,
+} from './standardizedFormData';
+import { xAxisControl } from 
'../../../plugins/plugin-chart-echarts/src/controls';
+
+describe('should collect control values and create SFD', () => {
+  const sharedControlsFormData = {};
+  Object.entries(sharedControls).forEach(([, names]) => {
+    names.forEach(name => {
+      sharedControlsFormData[name] = name;
+    });
+  });
+  const publicControlsFormData = Object.fromEntries(
+    publicControls.map((name, idx) => [[name], idx]),
+  );
+  const sourceMockFormData: SqlaFormData = {
+    ...sharedControlsFormData,
+    ...publicControlsFormData,
+    datasource: '100__table',
+    viz_type: 'source_viz',
+  };
+  const sourceMockStore = {
+    form_data: sourceMockFormData,
+    controls: Object.fromEntries(
+      Object.entries(sourceMockFormData).map(([key, value]) => [
+        key,
+        { value },
+      ]),
+    ),
+    datasource: {
+      type: 'table',
+      columns: [],
+    },
+  };
+  beforeAll(() => {
+    getChartControlPanelRegistry().registerValue('source_viz', {
+      controlPanelSections: [
+        sections.advancedAnalyticsControls,
+        {
+          label: 'transform controls',
+          controlSetRows: publicControls.map(control => [control]),
+        },
+        {
+          label: 'axis column',
+          controlSetRows: [xAxisControl],
+        },
+      ],
+    });
+    getChartControlPanelRegistry().registerValue('target_viz', {
+      controlPanelSections: [
+        sections.advancedAnalyticsControls,
+        {
+          label: 'transform controls',
+          controlSetRows: publicControls.map(control => [control]),
+        },
+        {
+          label: 'axis column',
+          controlSetRows: [[xAxisControl]],
+        },
+      ],
+      denormalizeFormData: (formData: SqlaFormData) => ({
+        ...formData,
+        columns: formData.standardized_form_data.sharedFormData.columns,
+        metrics: formData.standardized_form_data.sharedFormData.metrics,
+      }),
+    });
+  });
+
+  test('collect sharedControls', () => {
+    const sfd = new StandardizedFormData(sourceMockFormData);
+
+    expect(sfd.dumpSFD().sharedFormData.metrics).toEqual(
+      sharedControls.metrics.map(controlName => controlName),
+    );
+    expect(sfd.dumpSFD().sharedFormData.columns).toEqual(
+      sharedControls.columns.map(controlName => controlName),
+    );
+  });
+
+  test('should transform all publicControls', () => {
+    const sfd = new StandardizedFormData(sourceMockFormData);
+    const { formData } = sfd.transform('target_viz', sourceMockStore);
+    Object.entries(publicControlsFormData).forEach(([key]) => {
+      expect(formData).toHaveProperty(key);
+    });
+    Object.entries(sharedControls).forEach(([key, value]) => {
+      expect(formData[key]).toEqual(value);
+    });
+  });
+});
+
+describe('should transform form_data between table and bigNumberTotal', () => {
+  const tableVizFormData = {
+    datasource: '30__table',
+    viz_type: 'table',
+    time_grain_sqla: 'P1D',
+    time_range: 'No filter',
+    query_mode: 'aggregate',
+    groupby: ['name'],
+    metrics: ['count'],
+    all_columns: [],
+    percent_metrics: [],
+    adhoc_filters: [],
+    order_by_cols: [],
+    row_limit: 10000,
+    server_page_length: 10,
+    order_desc: true,
+    table_timestamp_format: 'smart_date',
+    show_cell_bars: true,
+    color_pn: true,
+    applied_time_extras: {},
+    url_params: {
+      form_data_key:
+        'p3No_sqDW7k-kMTzlBPAPd9vwp1IXTf6stbyzjlrPPa0ninvdYUUiMC6F1iKit3Y',
+      dataset_id: '30',
+    },
+  };
+  const tableVizStore = {
+    form_data: tableVizFormData,
+    controls: {
+      datasource: {
+        value: '30__table',
+      },
+      viz_type: {
+        value: 'table',
+      },
+      slice_id: {},
+      cache_timeout: {},
+      url_params: {
+        value: {
+          form_data_key:
+            'p3No_sqDW7k-kMTzlBPAPd9vwp1IXTf6stbyzjlrPPa0ninvdYUUiMC6F1iKit3Y',
+          dataset_id: '30',
+        },
+      },
+      granularity_sqla: {},
+      time_grain_sqla: {
+        value: 'P1D',
+      },
+      time_range: {
+        value: 'No filter',
+      },
+      query_mode: {
+        value: 'aggregate',
+      },
+      groupby: {
+        value: ['name'],
+      },
+      metrics: {
+        value: ['count'],
+      },
+      all_columns: {
+        value: [],
+      },
+      percent_metrics: {
+        value: [],
+      },
+      adhoc_filters: {
+        value: [],
+      },
+      timeseries_limit_metric: {},
+      order_by_cols: {
+        value: [],
+      },
+      server_pagination: {},
+      row_limit: {
+        value: 10000,
+      },
+      server_page_length: {
+        value: 10,
+      },
+      include_time: {},
+      order_desc: {
+        value: true,
+      },
+      show_totals: {},
+      emit_filter: {},
+      table_timestamp_format: {
+        value: 'smart_date',
+      },
+      page_length: {},
+      include_search: {},
+      show_cell_bars: {
+        value: true,
+      },
+      align_pn: {},
+      color_pn: {
+        value: true,
+      },
+      column_config: {},
+      conditional_formatting: {},
+    },
+    datasource: {
+      type: 'table',
+      columns: [],
+    },
+  };
+
+  beforeAll(() => {
+    getChartControlPanelRegistry().registerValue(
+      'big_number_total',
+      new BigNumberTotalChartPlugin().controlPanel,
+    );
+    getChartControlPanelRegistry().registerValue(
+      'table',
+      new TableChartPlugin().controlPanel,
+    );
+  });
+
+  test('transform', () => {
+    // table -> bigNumberTotal
+    const sfd = new StandardizedFormData(tableVizFormData);
+    const { formData: bntFormData, controlsState: btnControlsState } =

Review Comment:
   Nice catch! it's a typo.



-- 
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]

Reply via email to