sadpandajoe commented on code in PR #44945:
URL: https://github.com/apache/superset/pull/44945#discussion_r4273506079


##########
superset-frontend/src/explore/components/controls/ColumnConfigControl/ControlForm/ControlForm.test.tsx:
##########
@@ -0,0 +1,85 @@
+/**
+ * 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 { fireEvent, render, screen, act } from 'spec/helpers/testing-library';
+import ControlForm, { ControlFormItem, ControlFormRow } from './index';
+
+test('commits displayed default when clicking default option without initial 
value', () => {
+  jest.useFakeTimers();
+  const onChange = jest.fn();
+  const { rerender } = render(
+    <ControlForm onChange={onChange}>
+      <ControlFormRow>
+        <ControlFormItem
+          name="horizontalAlign"
+          controlType="RadioButtonControl"
+          label="Text align"
+          description=""
+          defaultValue="right"
+          debounceDelay={50}
+          options={[
+            ['left', 'Left'],
+            ['center', 'Center'],
+            ['right', 'Right'],
+          ]}
+        />
+      </ControlFormRow>
+    </ControlForm>,
+  );
+
+  const rightOption = screen.getByText('Right');
+  fireEvent.click(rightOption);
+
+  act(() => {
+    jest.advanceTimersByTime(100);
+  });
+
+  expect(onChange).toHaveBeenCalledTimes(1);
+  expect(onChange).toHaveBeenCalledWith({ horizontalAlign: 'right' });
+
+  // Re-render with committed value
+  rerender(
+    <ControlForm onChange={onChange} value={{ horizontalAlign: 'right' }}>
+      <ControlFormRow>
+        <ControlFormItem
+          name="horizontalAlign"
+          controlType="RadioButtonControl"
+          label="Text align"
+          description=""
+          defaultValue="right"
+          debounceDelay={50}
+          options={[
+            ['left', 'Left'],
+            ['center', 'Center'],
+            ['right', 'Right'],
+          ]}
+        />
+      </ControlFormRow>
+    </ControlForm>,
+  );
+
+  fireEvent.click(rightOption);
+
+  act(() => {
+    jest.advanceTimersByTime(100);
+  });
+
+  expect(onChange).toHaveBeenCalledTimes(1);

Review Comment:
   This assertion contradicts the behavior the PR now implements, and it is why 
`sharded-jest-tests (1)` fails on this head (expected 1 call, received 2). 
After the rerender with `value={{ horizontalAlign: 'right' }}`, clicking the 
already-selected "Right" goes through the `val === currentValue` branch in 
`RadioButtonControl`'s `onClick`, which intentionally calls `onChange` again, 
and `ControlFormItem` forwards it without an equality check, so a second 
debounced commit fires. The unused `_initialValue` can't suppress it either. 
Should this assert two calls with the same `{ horizontalAlign: 'right' }` 
payload, or is the re-click meant to be suppressed when the value is already 
persisted?



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