jesperct commented on code in PR #41208:
URL: https://github.com/apache/superset/pull/41208#discussion_r3446542622


##########
superset-frontend/src/explore/components/controls/MetricControl/MetricsControl.test.tsx:
##########
@@ -124,6 +124,48 @@ test('accepts an edited metric from an 
AdhocMetricEditPopover', async () => {
   ]);
 });
 
+test('only edits the targeted metric when two metrics share an optionName', 
async () => {
+  // A saved chart can carry two adhoc metrics with the same optionName (e.g.
+  // born from a duplicated metric). Editing one must not overwrite the other.
+  // Saved charts store metrics as plain dictionaries in form_data, so mirror
+  // that shape (not AdhocMetric instances) to exercise the real load path.
+  const sharedOptionName = 'metric_shared_option';
+  const { onChange } = setup({
+    value: [
+      {
+        expressionType: EXPRESSION_TYPES.SIMPLE,
+        column: valueColumn,
+        aggregate: AGGREGATES.SUM,
+        label: 'SUM(value)',
+        optionName: sharedOptionName,
+      },
+      {
+        expressionType: EXPRESSION_TYPES.SIMPLE,
+        column: valueColumn,
+        aggregate: AGGREGATES.AVG,
+        label: 'AVG(value)',
+        optionName: sharedOptionName,
+      },
+    ],
+  });
+
+  userEvent.click(screen.getByText('SUM(value)'));
+  await screen.findByText('aggregate');
+  await selectOption('MAX', 'Select aggregate options');
+  await screen.findByText('MAX(value)');
+  userEvent.click(screen.getByRole('button', { name: /save/i }));
+
+  // The untouched AVG(value) metric must still be present and unchanged.
+  expect(onChange).toHaveBeenCalledWith(
+    expect.arrayContaining([
+      expect.objectContaining({
+        aggregate: AGGREGATES.AVG,
+        label: 'AVG(value)',
+      }),
+    ]),
+  );

Review Comment:
   Strengthened the assertion to also check the edited metric saved as 
MAX(value), so a dropped edit can't pass on the surviving AVG alone. dfc4266.



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