codeant-ai-for-open-source[bot] commented on code in PR #38165:
URL: https://github.com/apache/superset/pull/38165#discussion_r3471083464


##########
superset-frontend/src/explore/components/DataTablesPane/test/useResultsPane.test.tsx:
##########
@@ -0,0 +1,191 @@
+/**
+ * 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 { screen, render, waitFor } from 'spec/helpers/testing-library';
+import { setupAGGridModules } from 
'@superset-ui/core/components/ThemedAgGridReact';
+import { getChartDataRequest } from 'src/components/Chart/chartAction';
+import { ResultsPaneOnDashboard } from '../components';
+import { createResultsPaneOnDashboardProps } from './fixture';
+
+// useResultsPane reaches the backend through getChartDataRequest. Mocking it
+// lets us assert *whether* a network request happens for each branch
+// (reuse-from-Redux vs. legacy API fallback).
+jest.mock('src/components/Chart/chartAction', () => ({
+  getChartDataRequest: jest.fn(),
+}));
+
+const mockedGetChartDataRequest = getChartDataRequest as jest.Mock;
+
+beforeAll(() => {
+  setupAGGridModules();
+});
+
+// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from 
describe blocks
+describe('useResultsPane query data reuse', () => {
+  beforeEach(() => {
+    mockedGetChartDataRequest.mockReset();
+  });
+
+  test('reuses queriesResponse from Redux and skips the results API call (v1 
charts)', async () => {
+    const queriesResponse = [
+      {
+        colnames: ['genre'],
+        coltypes: [1],
+        data: [{ genre: 'Action' }, { genre: 'Horror' }],
+        rowcount: 2,
+      },
+    ];
+    const props = createResultsPaneOnDashboardProps({
+      sliceId: 201,
+      queriesResponse,
+    });
+
+    render(<ResultsPaneOnDashboard {...props} />, { useRedux: true });
+
+    // Data renders straight from Redux...
+    expect(await screen.findByText('Action')).toBeVisible();
+    expect(screen.getByText('Horror')).toBeVisible();
+    // ...and no duplicate results request is fired.
+    expect(mockedGetChartDataRequest).not.toHaveBeenCalled();
+  });
+
+  test('falls back to the results API for legacy charts without a typed 
queriesResponse', async () => {
+    mockedGetChartDataRequest.mockResolvedValue({
+      json: {
+        result: [
+          {
+            colnames: ['genre'],
+            coltypes: [1],
+            data: [{ genre: 'Drama' }],
+            rowcount: 1,
+          },
+        ],
+      },
+    });
+    const props = createResultsPaneOnDashboardProps({
+      sliceId: 202,
+      // no queriesResponse -> legacy path
+    });
+
+    render(<ResultsPaneOnDashboard {...props} />, { useRedux: true });
+
+    expect(await screen.findByText('Drama')).toBeVisible();
+    expect(mockedGetChartDataRequest).toHaveBeenCalledTimes(1);
+  });
+
+  test('falls back to the results API when queriesResponse is untyped (no 
colnames)', async () => {
+    mockedGetChartDataRequest.mockResolvedValue({
+      json: {
+        result: [
+          {
+            colnames: ['genre'],
+            coltypes: [1],
+            data: [{ genre: 'Thriller' }],
+            rowcount: 1,
+          },
+        ],
+      },
+    });
+    const props = createResultsPaneOnDashboardProps({
+      sliceId: 203,
+      // legacy shape: present but without the v1 `colnames` discriminator
+      queriesResponse: [{ data: [{ genre: 'ignored' }] }] as any,

Review Comment:
   **Suggestion:** Replace the `any` cast with a concrete test-safe type (or a 
narrow reusable generic/union) that represents the legacy `queriesResponse` 
shape without disabling type checking. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The file is a new/modified TypeScript test file, and it contains an explicit 
`as any` cast. This directly violates the rule against using `any` in changed 
TypeScript/TSX code, so the suggestion is verified.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=86c909208601430d8b774e08f0fd1ea9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=86c909208601430d8b774e08f0fd1ea9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/explore/components/DataTablesPane/test/useResultsPane.test.tsx
   **Line:** 107:107
   **Comment:**
        *Custom Rule: Replace the `any` cast with a concrete test-safe type (or 
a narrow reusable generic/union) that represents the legacy `queriesResponse` 
shape without disabling type checking.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38165&comment_hash=812d11532b1b5312222f87d9d28eda94d5603df44e8ec6975ee410cdfcbdfe4b&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38165&comment_hash=812d11532b1b5312222f87d9d28eda94d5603df44e8ec6975ee410cdfcbdfe4b&reaction=dislike'>👎</a>



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