Copilot commented on code in PR #45064:
URL: https://github.com/apache/superset/pull/45064#discussion_r4222120580


##########
superset-frontend/packages/superset-ui-chart-controls/test/shared-controls/components/RadioButtonControl.test.tsx:
##########
@@ -88,29 +88,24 @@ test('respects initial value prop', () => {
   expect(secondButton).toHaveAttribute('aria-selected', 'true');
 });
 
-test('calls onChange when radio button is clicked', () => {
+test('calls onChange once when selecting a different radio button', () => {
   const onChange = jest.fn();
   setup({ onChange });
 
   const secondOption = screen.getByText('Option 2');
   fireEvent.click(secondOption);
 
   expect(onChange).toHaveBeenCalledWith('option2');
-  expect(onChange).toHaveBeenCalled();
+  expect(onChange).toHaveBeenCalledTimes(1);
 });
 
-test('handles multiple clicks correctly', () => {
+test('does not call onChange when clicking the selected radio button', () => {
   const onChange = jest.fn();
   setup({ onChange });
 
-  fireEvent.click(screen.getByText('Option 2'));
-  fireEvent.click(screen.getByText('Option 3'));
   fireEvent.click(screen.getByText('Option 1'));
 
-  expect(onChange).toHaveBeenCalledWith('option2');
-  expect(onChange).toHaveBeenCalledWith('option3');
-  expect(onChange).toHaveBeenCalledWith('option1');
-  expect(onChange.mock.calls.length).toBeGreaterThanOrEqual(3);
+  expect(onChange).not.toHaveBeenCalled();
 });

Review Comment:
   This test does not actually guarantee it's clicking an already-selected 
option. Unless the default selected value is known to be `Option 1` (and 
asserted), the click may change selection and legitimately call `onChange`, 
making the test brittle. Make the selected value explicit (e.g., render with 
`value: 'option1'` or assert the initial `aria-selected` state for Option 1 
before clicking), then click Option 1 and assert `onChange` remains uncalled.



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