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


##########
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:
   The re-click is intentionally not suppressed when the value is already 
persisted, because as discussed previously, ZoomConfigControl and Cartodiagram 
rely on re-clicking the active option to rebuild uniform sizes or restore 
drifted local state.
   
   In commit `db45fac32d`, we:
   1. Updated `ControlForm.test.tsx` to assert two calls 
(`expect(onChange).toHaveBeenCalledTimes(2)` and 
`expect(onChange).toHaveBeenLastCalledWith({ horizontalAlign: 'right' })`), 
matching the intentional re-click behavior and resolving the 
`sharded-jest-tests (1)` failure.
   2. Removed the dead `initialValue` prop forwarding in `ControlFormItem.tsx` 
(`<Control {...props} value={value} onChange={handleChange} />`), eliminating 
the unused plumbing.



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