bito-code-review[bot] commented on code in PR #37880:
URL: https://github.com/apache/superset/pull/37880#discussion_r3366473856
##########
superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.test.tsx:
##########
@@ -41,16 +44,34 @@ import {
} from
'src/explore/components/controls/DndColumnSelectControl/DndFilterSelect';
import { PLACEHOLDER_DATASOURCE } from 'src/dashboard/constants';
import { ExpressionTypes } from '../FilterControl/types';
-import { Datasource } from '../../../types';
import { DndItemType } from '../../DndItemType';
-import DatasourcePanelDragOption from
'../../DatasourcePanel/DatasourcePanelDragOption';
+import { Datasource } from '../../../types';
+import {
+ CapturedDroppable,
+ captureDroppableData,
+ simulateDrop,
+} from './dndTestUtils';
jest.mock('src/core/editors', () => ({
EditorHost: ({ value }: { value: string }) => (
<div data-test="react-ace">{value}</div>
),
}));
+jest.mock('@dnd-kit/core', () => ({
+ ...jest.requireActual('@dnd-kit/core'),
+ useDroppable: jest.fn(),
+}));
+
+const captured: CapturedDroppable = { current: undefined };
+
+beforeEach(() => {
+ captured.current = undefined;
+ (useDroppable as jest.Mock).mockImplementation(
+ captureDroppableData(captured),
+ );
+});
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Duplicate beforeEach causes mock reset</b></div>
<div id="fix">
The first `beforeEach` (line 68) sets `useDroppable` mock with
`captureDroppableData`, but the second `beforeEach` (line 120) calls
`jest.clearAllMocks()` which erases that implementation. Tests calling
`simulateDrop` on lines 227, 235, 255, 294, 329, 338, and 347 will have
`captured.current === undefined`, causing those drop simulations to fail
silently.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
---
a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.test.tsx
+++
b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.test.tsx
@@ -66,9 +66,10 @@ const captured: CapturedDroppable = { current: undefined
};
beforeEach(() => {
captured.current = undefined;
+ jest.clearAllMocks();
(useDroppable as jest.Mock).mockImplementation(
captureDroppableData(captured),
);
});
-beforeEach(() => {
- jest.clearAllMocks();
-});
```
</div>
</details>
</div>
<small><i>Code Review Run #ef9ae4</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]