You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "sadpandajoe (via GitHub)" <gi...@apache.org> on 2026/09/25 23:09:02 UTC

[PR] test(dashboard): cover edit-mode drag-and-drop drop rules [superset]

sadpandajoe opened a new pull request, #44678:
URL: https://github.com/apache/superset/pull/44678

   ### SUMMARY
   Adds unit tests for the dashboard edit-mode drag-and-drop rules:
   
   - `handleDrop` rejects forbidden and null drop positions and unmounted components without calling `onDrop` or clearing the drop cache, while still clearing the drop indicator.
   - When moving an item later within the same parent, the destination index is shifted down by one; it is not shifted for same-type items, items from a different parent, or items moving to an earlier index.
   - `dropToChild` (boolean or function) appends the item to the target's children, including an empty container; a function returning false drops the item next to the target in its parent instead.
   - Without a parent component, the item drops at the component's index; the drop cache is cleared after a successful drop.
   - The DragDroppable drag/drop config gates `canDrag`/`canDrop` on `disableDragDrop`, captures parent fields in `beginDrag`, guards `hover` and `drop` against unmounted targets and already-handled nested drops, and maps monitor state to props (including the idle state where nothing is being dragged).
   
   `getDropPosition` and `handleHover` are mocked here to isolate these layers; `getDropPosition` has its own existing tests.
   
   Test-only change; no production code is modified. Each new assertion was verified to fail when the guarded production line is temporarily broken.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A (tests only)
   
   ### TESTING INSTRUCTIONS
   ```bash
   cd superset-frontend
   npm run test -- src/dashboard/components/dnd/handleDrop.test.ts src/dashboard/components/dnd/dragDroppableConfig.test.ts
   ```
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   πŸ€– Generated with [Claude Code](https://claude.com/claude-code)


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] test(dashboard): cover edit-mode drag-and-drop drop rules [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44678:
URL: https://github.com/apache/superset/pull/44678#issuecomment-5840882238

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] test(dashboard): cover edit-mode drag-and-drop drop rules [superset]

Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #44678:
URL: https://github.com/apache/superset/pull/44678#issuecomment-5876181930

   ### <span aria-hidden="true">βœ…</span> Deploy Preview for *superset-docs-preview* ready!
   
   
   |  Name | Link |
   |:-:|------------------------|
   |<span aria-hidden="true">πŸ”¨</span> Latest commit | 3d668b28caa592e6128b490878a025ad5479b0ea |
   |<span aria-hidden="true">πŸ”</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6abab30d956c6b000844efee |
   |<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-44678--superset-docs-preview.netlify.app](https://deploy-preview-44678--superset-docs-preview.netlify.app) |
   |<span aria-hidden="true">πŸ“±</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTQ0Njc4LS1zdXBlcnNldC1kb2NzLXByZXZpZXcubmV0bGlmeS5hcHAifQ.SoR5hEMH_jv4zot6X4ZCcn8LTJp7ZeOwTZm6NC_VVfM)<br /><br />_Use your smartphone camera to open QR code link._</details> |
   |<span aria-hidden="true">πŸ€–</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DcoxDoAgDADAv3TW2EQk6g98RktrGBAI4GCMf5fthnshl3TlBjvAAFwoOt_dtLZJqHpOVGSUKGO5g9Z-RHNIzyF9WWLiGWVbrLOMiKsxeqrC9wM) |
   ---
   <!-- [superset-docs-preview Preview](https://deploy-preview-44678--superset-docs-preview.netlify.app) -->
   _To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] test(dashboard): cover edit-mode drag-and-drop drop rules [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #44678:
URL: https://github.com/apache/superset/pull/44678#discussion_r4109358004


##########
superset-frontend/src/dashboard/components/dnd/dragDroppableConfig.test.ts:
##########
@@ -0,0 +1,268 @@
+/**
+ * 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 { DragSourceMonitor, DropTargetMonitor } from 'react-dnd';
+import { CHART_TYPE } from '../../util/componentTypes';
+import type {
+  DragDroppableComponent,
+  DragDroppableProps,
+  DropResult,
+} from './dragDroppableConfig';
+
+jest.mock('./handleHover', () => ({
+  __esModule: true,
+  default: jest.fn(),
+}));
+jest.mock('./handleDrop', () => ({
+  __esModule: true,
+  default: jest.fn(),
+}));
+
+// imports follow the jest.mock calls to mirror their hoisted order
+// eslint-disable-next-line import/first
+import { dragConfig, dropConfig } from './dragDroppableConfig';
+// eslint-disable-next-line import/first
+import mockedHandleHover from './handleHover';
+// eslint-disable-next-line import/first
+import mockedHandleDrop from './handleDrop';
+
+const { canDrag, beginDrag } = dragConfig[1];
+const { canDrop, hover, drop } = dropConfig[1];
+
+function makeProps(
+  overrides: Partial<DragDroppableProps> = {},
+): DragDroppableProps {
+  return {
+    component: {
+      id: 'chart-1',
+      type: CHART_TYPE,
+      children: [],
+      meta: {},
+    },
+    index: 0,
+    depth: 1,
+    disableDragDrop: false,
+    ...overrides,
+  } as DragDroppableProps;
+}
+
+function makeComponent(
+  overrides: Partial<DragDroppableComponent> = {},
+): DragDroppableComponent {
+  return {
+    mounted: true,
+    props: makeProps(),
+    setState: jest.fn(),
+    ...overrides,
+  };
+}
+
+beforeEach(() => {
+  jest.clearAllMocks();
+});
+
+test('canDrag allows dragging when disableDragDrop is false', () => {
+  expect(canDrag(makeProps({ disableDragDrop: false }))).toBe(true);
+});
+
+test('canDrag forbids dragging when disableDragDrop is true', () => {
+  expect(canDrag(makeProps({ disableDragDrop: true }))).toBe(false);
+});
+
+test('beginDrag captures the parent id and type when a parent component is present', () => {
+  const parentComponent = {
+    id: 'row-1',
+    type: 'ROW',

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Magic string 'ROW' instead of ROW_TYPE</b></div>
   <div id="fix">
   
   This fixture hardcodes the component-type string 'ROW' (asserted again as parentType at line 102) while importing CHART_TYPE from the same `../../util/componentTypes` module, which already exports `ROW_TYPE = 'ROW'`. Using the exported constant keeps the fixture consistent with the production `ComponentType` union and survives a future rename. Suggest `import { CHART_TYPE, ROW_TYPE }` and using `ROW_TYPE` in both places.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #36d094</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



##########
superset-frontend/src/dashboard/components/dnd/dragDroppableConfig.test.ts:
##########
@@ -0,0 +1,268 @@
+/**
+ * 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 { DragSourceMonitor, DropTargetMonitor } from 'react-dnd';
+import { CHART_TYPE } from '../../util/componentTypes';
+import type {
+  DragDroppableComponent,
+  DragDroppableProps,
+  DropResult,
+} from './dragDroppableConfig';
+
+jest.mock('./handleHover', () => ({
+  __esModule: true,
+  default: jest.fn(),
+}));
+jest.mock('./handleDrop', () => ({
+  __esModule: true,
+  default: jest.fn(),
+}));
+
+// imports follow the jest.mock calls to mirror their hoisted order
+// eslint-disable-next-line import/first
+import { dragConfig, dropConfig } from './dragDroppableConfig';
+// eslint-disable-next-line import/first
+import mockedHandleHover from './handleHover';
+// eslint-disable-next-line import/first
+import mockedHandleDrop from './handleDrop';
+
+const { canDrag, beginDrag } = dragConfig[1];
+const { canDrop, hover, drop } = dropConfig[1];
+
+function makeProps(
+  overrides: Partial<DragDroppableProps> = {},
+): DragDroppableProps {
+  return {
+    component: {
+      id: 'chart-1',
+      type: CHART_TYPE,
+      children: [],
+      meta: {},
+    },
+    index: 0,
+    depth: 1,
+    disableDragDrop: false,
+    ...overrides,
+  } as DragDroppableProps;
+}
+
+function makeComponent(
+  overrides: Partial<DragDroppableComponent> = {},
+): DragDroppableComponent {
+  return {
+    mounted: true,
+    props: makeProps(),
+    setState: jest.fn(),
+    ...overrides,
+  };
+}
+
+beforeEach(() => {
+  jest.clearAllMocks();
+});
+
+test('canDrag allows dragging when disableDragDrop is false', () => {
+  expect(canDrag(makeProps({ disableDragDrop: false }))).toBe(true);
+});
+
+test('canDrag forbids dragging when disableDragDrop is true', () => {
+  expect(canDrag(makeProps({ disableDragDrop: true }))).toBe(false);
+});
+
+test('beginDrag captures the parent id and type when a parent component is present', () => {
+  const parentComponent = {
+    id: 'row-1',
+    type: 'ROW',
+    children: [],
+    meta: {},
+  } as DragDroppableProps['parentComponent'];
+  const props = makeProps({ parentComponent, index: 2 });
+
+  expect(beginDrag(props)).toEqual({
+    type: CHART_TYPE,
+    id: 'chart-1',
+    meta: {},
+    index: 2,
+    parentId: 'row-1',
+    parentType: 'ROW',
+  });
+});
+
+test('beginDrag leaves parent fields undefined when there is no parent component', () => {
+  const props = makeProps({ parentComponent: undefined });
+
+  expect(beginDrag(props)).toEqual({
+    type: CHART_TYPE,
+    id: 'chart-1',
+    meta: {},
+    index: 0,
+    parentId: undefined,
+    parentType: undefined,
+  });
+});
+
+test('canDrop allows dropping when disableDragDrop is false', () => {
+  expect(canDrop(makeProps({ disableDragDrop: false }))).toBe(true);
+});
+
+test('canDrop forbids dropping when disableDragDrop is true', () => {
+  expect(canDrop(makeProps({ disableDragDrop: true }))).toBe(false);
+});
+
+test('hover delegates to handleHover when the drop target component is mounted', () => {
+  const props = makeProps();
+  const monitor = {} as DropTargetMonitor;
+  const component = makeComponent({ mounted: true });
+
+  hover(props, monitor, component);
+
+  expect(mockedHandleHover).toHaveBeenCalledWith(props, monitor, component);
+});
+
+test('hover does not call handleHover when the drop target component has unmounted', () => {
+  const props = makeProps();
+  const monitor = {} as DropTargetMonitor;
+  const component = makeComponent({ mounted: false });
+
+  hover(props, monitor, component);
+
+  expect(mockedHandleHover).not.toHaveBeenCalled();
+});
+
+test('drop delegates to handleDrop when no nested target already produced a result', () => {
+  const props = makeProps();
+  const component = makeComponent({ mounted: true });
+  const expected: DropResult = {
+    source: { id: 'a', type: CHART_TYPE, index: 0 },
+    dragging: { id: 'b', type: CHART_TYPE, meta: {} },
+  };

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Duplicated DropResult test literal</b></div>
   <div id="fix">
   
   The `DropResult` literal `{ source: { id: 'a', ... }, dragging: { id: 'b', ... } }` is repeated three times in this diff (lines 150-153, 169-172, 184-188). The file already establishes factory helpers `makeProps` and `makeComponent` for shared test data; a `makeDropResult(overrides?)` helper would keep the three `drop` tests in lockstep if the `DropResult` shape changes and match the file's own convention.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #36d094</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



##########
superset-frontend/src/dashboard/components/dnd/dragDroppableConfig.test.ts:
##########
@@ -0,0 +1,268 @@
+/**
+ * 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 { DragSourceMonitor, DropTargetMonitor } from 'react-dnd';
+import { CHART_TYPE } from '../../util/componentTypes';
+import type {
+  DragDroppableComponent,
+  DragDroppableProps,
+  DropResult,
+} from './dragDroppableConfig';
+
+jest.mock('./handleHover', () => ({
+  __esModule: true,
+  default: jest.fn(),
+}));
+jest.mock('./handleDrop', () => ({
+  __esModule: true,
+  default: jest.fn(),
+}));
+
+// imports follow the jest.mock calls to mirror their hoisted order
+// eslint-disable-next-line import/first
+import { dragConfig, dropConfig } from './dragDroppableConfig';
+// eslint-disable-next-line import/first
+import mockedHandleHover from './handleHover';
+// eslint-disable-next-line import/first
+import mockedHandleDrop from './handleDrop';
+
+const { canDrag, beginDrag } = dragConfig[1];
+const { canDrop, hover, drop } = dropConfig[1];
+
+function makeProps(
+  overrides: Partial<DragDroppableProps> = {},
+): DragDroppableProps {
+  return {
+    component: {
+      id: 'chart-1',
+      type: CHART_TYPE,
+      children: [],
+      meta: {},
+    },
+    index: 0,
+    depth: 1,
+    disableDragDrop: false,
+    ...overrides,
+  } as DragDroppableProps;
+}
+
+function makeComponent(
+  overrides: Partial<DragDroppableComponent> = {},
+): DragDroppableComponent {
+  return {
+    mounted: true,
+    props: makeProps(),
+    setState: jest.fn(),
+    ...overrides,
+  };
+}
+
+beforeEach(() => {
+  jest.clearAllMocks();
+});
+
+test('canDrag allows dragging when disableDragDrop is false', () => {
+  expect(canDrag(makeProps({ disableDragDrop: false }))).toBe(true);
+});
+
+test('canDrag forbids dragging when disableDragDrop is true', () => {
+  expect(canDrag(makeProps({ disableDragDrop: true }))).toBe(false);
+});
+
+test('beginDrag captures the parent id and type when a parent component is present', () => {
+  const parentComponent = {
+    id: 'row-1',
+    type: 'ROW',
+    children: [],
+    meta: {},
+  } as DragDroppableProps['parentComponent'];
+  const props = makeProps({ parentComponent, index: 2 });
+
+  expect(beginDrag(props)).toEqual({
+    type: CHART_TYPE,
+    id: 'chart-1',
+    meta: {},
+    index: 2,
+    parentId: 'row-1',
+    parentType: 'ROW',
+  });
+});
+
+test('beginDrag leaves parent fields undefined when there is no parent component', () => {
+  const props = makeProps({ parentComponent: undefined });
+
+  expect(beginDrag(props)).toEqual({
+    type: CHART_TYPE,
+    id: 'chart-1',
+    meta: {},
+    index: 0,
+    parentId: undefined,
+    parentType: undefined,
+  });
+});
+
+test('canDrop allows dropping when disableDragDrop is false', () => {
+  expect(canDrop(makeProps({ disableDragDrop: false }))).toBe(true);
+});
+
+test('canDrop forbids dropping when disableDragDrop is true', () => {
+  expect(canDrop(makeProps({ disableDragDrop: true }))).toBe(false);
+});
+
+test('hover delegates to handleHover when the drop target component is mounted', () => {
+  const props = makeProps();
+  const monitor = {} as DropTargetMonitor;
+  const component = makeComponent({ mounted: true });
+
+  hover(props, monitor, component);
+
+  expect(mockedHandleHover).toHaveBeenCalledWith(props, monitor, component);
+});
+
+test('hover does not call handleHover when the drop target component has unmounted', () => {
+  const props = makeProps();
+  const monitor = {} as DropTargetMonitor;
+  const component = makeComponent({ mounted: false });
+
+  hover(props, monitor, component);
+
+  expect(mockedHandleHover).not.toHaveBeenCalled();
+});
+
+test('drop delegates to handleDrop when no nested target already produced a result', () => {
+  const props = makeProps();
+  const component = makeComponent({ mounted: true });
+  const expected: DropResult = {
+    source: { id: 'a', type: CHART_TYPE, index: 0 },
+    dragging: { id: 'b', type: CHART_TYPE, meta: {} },
+  };
+  (mockedHandleDrop as jest.Mock).mockReturnValueOnce(expected);
+  const monitor = {
+    getDropResult: jest.fn(() => null),
+  } as unknown as DropTargetMonitor;
+
+  const result = drop(props, monitor, component);
+
+  expect(mockedHandleDrop).toHaveBeenCalledWith(props, monitor, component);
+  expect(result).toBe(expected);
+});
+
+test('drop delegates to handleDrop when a nested result has no destination', () => {
+  const props = makeProps();
+  const component = makeComponent({ mounted: true });
+  const monitor = {
+    getDropResult: jest.fn(() => ({
+      source: { id: 'a', type: CHART_TYPE, index: 0 },
+      dragging: { id: 'b', type: CHART_TYPE, meta: {} },
+    })),
+  } as unknown as DropTargetMonitor;
+
+  drop(props, monitor, component);
+
+  expect(mockedHandleDrop).toHaveBeenCalledWith(props, monitor, component);
+});
+
+test('drop returns undefined and skips handleDrop when a nested target already produced a destination', () => {
+  const props = makeProps();
+  const component = makeComponent({ mounted: true });
+  const monitor = {
+    getDropResult: jest.fn(() => ({
+      source: { id: 'a', type: CHART_TYPE, index: 0 },
+      dragging: { id: 'b', type: CHART_TYPE, meta: {} },
+      destination: { id: 'c', type: CHART_TYPE, index: 1 },
+    })),
+  } as unknown as DropTargetMonitor;
+
+  const result = drop(props, monitor, component);
+
+  expect(result).toBeUndefined();
+  expect(mockedHandleDrop).not.toHaveBeenCalled();
+});
+
+test('drop returns undefined and skips handleDrop when the component has unmounted', () => {
+  const props = makeProps();
+  const component = makeComponent({ mounted: false });
+  const monitor = {
+    getDropResult: jest.fn(() => null),
+  } as unknown as DropTargetMonitor;
+
+  const result = drop(props, monitor, component);
+
+  expect(result).toBeUndefined();
+  expect(mockedHandleDrop).not.toHaveBeenCalled();
+});
+
+test('dragStateToProps reports isDragging and the dragged component identity from the monitor', () => {
+  const dragStateToProps = dragConfig[2];
+  const connect = {
+    dragSource: jest.fn(() => 'drag-source-ref'),
+    dragPreview: jest.fn(() => 'drag-preview-ref'),
+  };
+  const monitor = {
+    isDragging: jest.fn(() => true),
+    getItem: jest.fn(() => ({ id: 'chart-1', type: CHART_TYPE })),
+  } as unknown as DragSourceMonitor;

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Duplicated drag mock literals</b></div>
   <div id="fix">
   
   The `connect` and `monitor` mock literals for `dragStateToProps` are duplicated verbatim between this test and the one at lines 252-259. The file already centralizes mocks via `makeProps`/`makeComponent`; a shared factory would keep the two drag-state tests from diverging when `DragStateProps` grows a field.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #36d094</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



##########
superset-frontend/src/dashboard/components/dnd/dragDroppableConfig.test.ts:
##########
@@ -0,0 +1,268 @@
+/**
+ * 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 { DragSourceMonitor, DropTargetMonitor } from 'react-dnd';
+import { CHART_TYPE } from '../../util/componentTypes';
+import type {
+  DragDroppableComponent,
+  DragDroppableProps,
+  DropResult,
+} from './dragDroppableConfig';
+
+jest.mock('./handleHover', () => ({
+  __esModule: true,
+  default: jest.fn(),
+}));
+jest.mock('./handleDrop', () => ({
+  __esModule: true,
+  default: jest.fn(),
+}));
+
+// imports follow the jest.mock calls to mirror their hoisted order
+// eslint-disable-next-line import/first
+import { dragConfig, dropConfig } from './dragDroppableConfig';
+// eslint-disable-next-line import/first
+import mockedHandleHover from './handleHover';
+// eslint-disable-next-line import/first
+import mockedHandleDrop from './handleDrop';
+
+const { canDrag, beginDrag } = dragConfig[1];
+const { canDrop, hover, drop } = dropConfig[1];
+
+function makeProps(
+  overrides: Partial<DragDroppableProps> = {},
+): DragDroppableProps {
+  return {
+    component: {
+      id: 'chart-1',
+      type: CHART_TYPE,
+      children: [],
+      meta: {},
+    },
+    index: 0,
+    depth: 1,
+    disableDragDrop: false,
+    ...overrides,
+  } as DragDroppableProps;
+}
+
+function makeComponent(
+  overrides: Partial<DragDroppableComponent> = {},
+): DragDroppableComponent {
+  return {
+    mounted: true,
+    props: makeProps(),
+    setState: jest.fn(),
+    ...overrides,
+  };
+}
+
+beforeEach(() => {
+  jest.clearAllMocks();
+});
+
+test('canDrag allows dragging when disableDragDrop is false', () => {
+  expect(canDrag(makeProps({ disableDragDrop: false }))).toBe(true);
+});
+
+test('canDrag forbids dragging when disableDragDrop is true', () => {
+  expect(canDrag(makeProps({ disableDragDrop: true }))).toBe(false);
+});
+
+test('beginDrag captures the parent id and type when a parent component is present', () => {
+  const parentComponent = {
+    id: 'row-1',
+    type: 'ROW',
+    children: [],
+    meta: {},
+  } as DragDroppableProps['parentComponent'];
+  const props = makeProps({ parentComponent, index: 2 });
+
+  expect(beginDrag(props)).toEqual({
+    type: CHART_TYPE,
+    id: 'chart-1',
+    meta: {},
+    index: 2,
+    parentId: 'row-1',
+    parentType: 'ROW',
+  });
+});
+
+test('beginDrag leaves parent fields undefined when there is no parent component', () => {
+  const props = makeProps({ parentComponent: undefined });
+
+  expect(beginDrag(props)).toEqual({
+    type: CHART_TYPE,
+    id: 'chart-1',
+    meta: {},
+    index: 0,
+    parentId: undefined,
+    parentType: undefined,
+  });
+});
+
+test('canDrop allows dropping when disableDragDrop is false', () => {
+  expect(canDrop(makeProps({ disableDragDrop: false }))).toBe(true);
+});
+
+test('canDrop forbids dropping when disableDragDrop is true', () => {
+  expect(canDrop(makeProps({ disableDragDrop: true }))).toBe(false);
+});
+
+test('hover delegates to handleHover when the drop target component is mounted', () => {
+  const props = makeProps();
+  const monitor = {} as DropTargetMonitor;
+  const component = makeComponent({ mounted: true });
+
+  hover(props, monitor, component);
+
+  expect(mockedHandleHover).toHaveBeenCalledWith(props, monitor, component);
+});
+
+test('hover does not call handleHover when the drop target component has unmounted', () => {
+  const props = makeProps();
+  const monitor = {} as DropTargetMonitor;
+  const component = makeComponent({ mounted: false });
+
+  hover(props, monitor, component);
+
+  expect(mockedHandleHover).not.toHaveBeenCalled();
+});
+
+test('drop delegates to handleDrop when no nested target already produced a result', () => {
+  const props = makeProps();
+  const component = makeComponent({ mounted: true });
+  const expected: DropResult = {
+    source: { id: 'a', type: CHART_TYPE, index: 0 },
+    dragging: { id: 'b', type: CHART_TYPE, meta: {} },
+  };
+  (mockedHandleDrop as jest.Mock).mockReturnValueOnce(expected);
+  const monitor = {
+    getDropResult: jest.fn(() => null),
+  } as unknown as DropTargetMonitor;
+
+  const result = drop(props, monitor, component);
+
+  expect(mockedHandleDrop).toHaveBeenCalledWith(props, monitor, component);
+  expect(result).toBe(expected);
+});
+
+test('drop delegates to handleDrop when a nested result has no destination', () => {
+  const props = makeProps();
+  const component = makeComponent({ mounted: true });
+  const monitor = {
+    getDropResult: jest.fn(() => ({
+      source: { id: 'a', type: CHART_TYPE, index: 0 },
+      dragging: { id: 'b', type: CHART_TYPE, meta: {} },
+    })),
+  } as unknown as DropTargetMonitor;
+
+  drop(props, monitor, component);
+
+  expect(mockedHandleDrop).toHaveBeenCalledWith(props, monitor, component);
+});
+
+test('drop returns undefined and skips handleDrop when a nested target already produced a destination', () => {
+  const props = makeProps();
+  const component = makeComponent({ mounted: true });
+  const monitor = {
+    getDropResult: jest.fn(() => ({
+      source: { id: 'a', type: CHART_TYPE, index: 0 },
+      dragging: { id: 'b', type: CHART_TYPE, meta: {} },
+      destination: { id: 'c', type: CHART_TYPE, index: 1 },
+    })),
+  } as unknown as DropTargetMonitor;
+
+  const result = drop(props, monitor, component);
+
+  expect(result).toBeUndefined();
+  expect(mockedHandleDrop).not.toHaveBeenCalled();
+});
+
+test('drop returns undefined and skips handleDrop when the component has unmounted', () => {
+  const props = makeProps();
+  const component = makeComponent({ mounted: false });
+  const monitor = {
+    getDropResult: jest.fn(() => null),
+  } as unknown as DropTargetMonitor;
+
+  const result = drop(props, monitor, component);
+
+  expect(result).toBeUndefined();
+  expect(mockedHandleDrop).not.toHaveBeenCalled();
+});
+
+test('dragStateToProps reports isDragging and the dragged component identity from the monitor', () => {
+  const dragStateToProps = dragConfig[2];

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Magic tuple index accessors</b></div>
   <div id="fix">
   
   `dragConfig[2]`/`dropConfig[2]` reach the collect functions by bare tuple index, while the existing tests destructure `dragConfig[1]`/`dropConfig[1]` into named consts (`canDrag`, `beginDrag`, ...) at lines 44-45. Named destructuring would match the file's own convention and survive tuple reordering.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #36d094</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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] test(dashboard): cover edit-mode drag-and-drop drop rules [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44678:
URL: https://github.com/apache/superset/pull/44678#issuecomment-5879185654

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers an incremental AI Review.
   - `/review full` - Manually triggers a full AI Review.
   
   - `/pause` - Pauses automatic reviews on this pull request.
   - `/resume` - Resumes automatic reviews.
   - `/resolve` - Marks all Bito-posted review comments as resolved.
   - `/abort` - Cancels all in-progress reviews.
   
         
   Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] test(dashboard): cover edit-mode drag-and-drop drop rules [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas merged PR #44678:
URL: https://github.com/apache/superset/pull/44678


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] test(dashboard): cover edit-mode drag-and-drop drop rules [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #44678:
URL: https://github.com/apache/superset/pull/44678#issuecomment-5840968840

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/44678?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 81.11%. Comparing base ([`10ca640`](https://app.codecov.io/gh/apache/superset/commit/10ca640e97e0b03686fe2f243f6b5f0bd331ac1c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`94ed200`](https://app.codecov.io/gh/apache/superset/commit/94ed200265e0ed7899b93ecc7aa96502e4debcb4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #44678      +/-   ##
   ==========================================
   - Coverage   81.11%   81.11%   -0.01%     
   ==========================================
     Files        2955     2955              
     Lines      178335   178335              
     Branches    41311    41311              
   ==========================================
   - Hits       144665   144664       -1     
   - Misses      30967    30968       +1     
     Partials     2703     2703              
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/44678/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Ξ” | |
   |---|---|---|
   | [javascript](https://app.codecov.io/gh/apache/superset/pull/44678/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `76.50% <ΓΈ> (-0.01%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/44678?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org