bito-code-review[bot] commented on code in PR #35456:
URL: https://github.com/apache/superset/pull/35456#discussion_r2399639402


##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/components/DatasetUsageTab/DatasetUsageTab.test.tsx:
##########
@@ -101,21 +158,47 @@ const setupTest = (props = {}) => {
     ...props,
   };
 
-  return render(<DatasetUsageTab {...defaultProps} />, {
+  const result = render(<DatasetUsageTab {...defaultProps} />, {
     wrapper: createWrapper({
       useRedux: true,
       useRouter: true,
     }),
   });
+
+  return { ...result, mockOnFetchCharts };
 };
 
 beforeEach(() => {
   fetchMock.reset();
   jest.clearAllMocks();
+
+  // Save original scrollTo and mock it for JSDOM compatibility
+  originalScrollTo = Element.prototype.scrollTo;
+  Object.defineProperty(Element.prototype, 'scrollTo', {
+    value: jest.fn(),
+    configurable: true,
+    writable: true,
+  });
+
+  tableMock.__resetPaginationHandler();
 });
 
 afterEach(() => {
   fetchMock.restore();
+
+  // Restore real timers in case a test with fakeTimers failed mid-test
+  jest.useRealTimers();
+
+  // Restore original scrollTo to avoid test pollution
+  if (originalScrollTo) {
+    Object.defineProperty(Element.prototype, 'scrollTo', {
+      value: originalScrollTo,

Review Comment:
   
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing mock cleanup</b></div>
   <div id="fix">
   
   The new tests are missing proper cleanup of the scrollTo mock between tests. 
The existing afterEach hook only restores the original scrollTo if it was 
defined, but the new tests cast Element.prototype.scrollTo as jest.Mock without 
ensuring proper cleanup. This can cause test pollution where mock state 
persists between tests, leading to flaky test failures in CI environments. Add 
comprehensive mock cleanup to ensure test isolation.
   </div>
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```suggestion
       jest.useRealTimers();
    
       // Restore original scrollTo to avoid test pollution
       jest.restoreAllMocks();
       if (originalScrollTo) {
         Object.defineProperty(Element.prototype, 'scrollTo', {
           value: originalScrollTo,
   ```
   
   </div>
   </details>
   </div>
   
   
   
   <small><i>Code Review Run <a 
href=https://github.com/apache/superset/pull/35456#issuecomment-3362353707>#be8e30</a></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/components/Datasource/components/DatasourceEditor/components/DatasetUsageTab/DatasetUsageTab.test.tsx:
##########
@@ -25,6 +26,59 @@ import {
 import fetchMock from 'fetch-mock';
 import DatasetUsageTab from '.';
 
+jest.mock('@superset-ui/core/components/Table', () => {
+  const React = require('react');
+  const actual = jest.requireActual('@superset-ui/core/components/Table');
+  const ActualTable = actual.default;
+
+  let latestPaginationHandler: ((page: number, pageSize?: number) => void) | 
null = null;
+  let latestPaginationPageSize: number | undefined;
+  let latestOnChangeHandler:
+    | ((pagination: { current: number; pageSize?: number }) => void)
+    | null = null;
+
+  const MockTable = ({ pagination, onChange, ...rest }: any) => {
+    if (pagination?.pageSize) {
+      latestPaginationPageSize = pagination.pageSize;
+    }
+
+    if (typeof pagination?.onChange === 'function') {
+      latestPaginationHandler = pagination.onChange;
+    }

Review Comment:
   
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Incorrect mock handler capture</b></div>
   <div id="fix">
   
   The mock implementation has a critical flaw in how it captures the onChange 
handler. The mock is checking for `pagination?.onChange` but the actual Table 
component uses the top-level `onChange` prop, not nested within pagination. 
This causes the `__getLatestOnChangeHandler` to return null instead of the 
actual handler, breaking tests that depend on it. Remove the incorrect check 
for `pagination?.onChange` and only capture the top-level `onChange` prop.
   </div>
   <details>
   <summary>
   <b>Code suggestion</b>
   </summary>
   <blockquote>Check the AI-generated fix before applying</blockquote>
   <div id="code">
   
   
   ```suggestion
   
   ```
   
   </div>
   </details>
   </div>
   
   
   
   <small><i>Code Review Run <a 
href=https://github.com/apache/superset/pull/35456#issuecomment-3362353707>#be8e30</a></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]

Reply via email to