bito-code-review[bot] commented on code in PR #44148:
URL: https://github.com/apache/superset/pull/44148#discussion_r4176242940


##########
superset-frontend/plugins/preset-chart-deckgl/src/layers/Scatter/controlPanel.test.ts:
##########
@@ -0,0 +1,89 @@
+/**
+ * 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,
+  QueryFormData,
+  getChartControlPanelRegistry,
+} from '@superset-ui/core';
+import { ControlStateMapping } from '@superset-ui/chart-controls';
+import {
+  getAllControlsState,
+  getFormDataFromControls,
+} from 'src/explore/controlUtils';
+import controlPanel from './controlPanel';
+
+const controlNames = (): string[] =>
+  (controlPanel.controlPanelSections ?? [])
+    .flatMap(section => section?.controlSetRows ?? [])
+    .flat()
+    .map(item =>
+      typeof item === 'string'
+        ? item
+        : (item as { name?: string } | null)?.name,
+    )
+    .filter((name): name is string => Boolean(name));
+
+test('keeps the MCP geographic marker and row limit through Explore 
hydration', () => {
+  expect(controlNames()).toEqual(
+    expect.arrayContaining([
+      'mcp_geographic',
+      'row_limit',
+      '_mcp_dashboard_time_filter_subject',
+    ]),
+  );
+});
+
+test.each(['event_time', null])(
+  'Explore saves preserve dashboard-time provenance %s',
+  subject => {
+    const vizType = 'test-geographic-time-binding';
+    const registry = getChartControlPanelRegistry();
+    registry.registerValue(vizType, controlPanel);
+    try {
+      const input: QueryFormData = {
+        viz_type: vizType,
+        datasource: '3__table',
+        mcp_geographic: true,
+        _mcp_dashboard_time_filter_subject: subject,
+        adhoc_filters: subject
+          ? [
+              {
+                subject,
+                operator: 'TEMPORAL_RANGE',
+                comparator: 'No filter',
+                clause: 'WHERE',
+                expressionType: 'SIMPLE',
+              },
+            ]
+          : [],
+      };
+      const controls = getAllControlsState(
+        vizType,
+        DatasourceType.Table,
+        null,
+        input,
+      );
+      const saved = getFormDataFromControls(controls as ControlStateMapping);
+      expect(saved._mcp_dashboard_time_filter_subject).toBe(subject);
+      expect(saved.adhoc_filters).toEqual(input.adhoc_filters);
+    } finally {
+      registry.remove(vizType);
+    }
+  },
+);

Review Comment:
   <!-- Bito Reply -->
   The suggestion to extract the duplicated test block into a shared helper is 
appropriate and improves the maintainability of the test suite. By centralizing 
the parameterized hydration and provenance test, you reduce code duplication 
and ensure that future changes to the contract only need to be updated in one 
location. The implementation described, which moves the logic to a helper file 
and invokes it from the control-panel test files, is a standard and recommended 
practice for this type of refactoring.



##########
superset-frontend/plugins/plugin-chart-country-map/test/controlPanel.test.ts:
##########
@@ -0,0 +1,89 @@
+/**
+ * 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,
+  QueryFormData,
+  getChartControlPanelRegistry,
+} from '@superset-ui/core';
+import { ControlStateMapping } from '@superset-ui/chart-controls';
+import {
+  getAllControlsState,
+  getFormDataFromControls,
+} from 'src/explore/controlUtils';
+import controlPanel from '../src/controlPanel';
+
+const controlNames = (): string[] =>
+  (controlPanel.controlPanelSections ?? [])
+    .flatMap(section => section?.controlSetRows ?? [])
+    .flat()
+    .map(item =>
+      typeof item === 'string'
+        ? item
+        : (item as { name?: string } | null)?.name,
+    )
+    .filter((name): name is string => Boolean(name));
+
+test('keeps the MCP geographic marker and row limit through Explore 
hydration', () => {
+  expect(controlNames()).toEqual(
+    expect.arrayContaining([
+      'mcp_geographic',
+      'row_limit',
+      '_mcp_dashboard_time_filter_subject',
+    ]),
+  );
+});
+
+test.each(['event_time', null])(
+  'Explore saves preserve dashboard-time provenance %s',
+  subject => {
+    const vizType = 'test-geographic-time-binding';
+    const registry = getChartControlPanelRegistry();
+    registry.registerValue(vizType, controlPanel);
+    try {
+      const input: QueryFormData = {
+        viz_type: vizType,
+        datasource: '3__table',
+        mcp_geographic: true,
+        _mcp_dashboard_time_filter_subject: subject,
+        adhoc_filters: subject
+          ? [
+              {
+                subject,
+                operator: 'TEMPORAL_RANGE',
+                comparator: 'No filter',
+                clause: 'WHERE',
+                expressionType: 'SIMPLE',
+              },
+            ]
+          : [],
+      };
+      const controls = getAllControlsState(
+        vizType,
+        DatasourceType.Table,
+        null,
+        input,
+      );
+      const saved = getFormDataFromControls(controls as ControlStateMapping);
+      expect(saved._mcp_dashboard_time_filter_subject).toBe(subject);
+      expect(saved.adhoc_filters).toEqual(input.adhoc_filters);
+    } finally {
+      registry.remove(vizType);
+    }
+  },
+);

Review Comment:
   <!-- Bito Reply -->
   The suggestion to extract the duplicated test block into a shared helper is 
valid and improves maintainability by preventing drift across the three test 
suites. Since the behavior under test relies on shared utilities, centralizing 
the parameterized test logic is a standard best practice for reducing code 
duplication.



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