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


##########
superset-frontend/plugins/plugin-chart-table/test/DataTable/DataTable.test.tsx:
##########
@@ -0,0 +1,127 @@
+/**
+ * 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 '@testing-library/jest-dom';
+import { Component, type ReactNode } from 'react';
+import { render, screen } from '@superset-ui/core/spec';
+import { CellProps, Column, HeaderProps } from 'react-table';
+import DataTable from '../../src/DataTable/DataTable';
+import { ProviderWrapper } from '../testHelpers';
+
+type DataRow = {
+  city: string;
+  firstName: string;
+};
+
+interface RenderErrorBoundaryProps {
+  children: ReactNode;
+}
+
+interface RenderErrorBoundaryState {
+  hasError: boolean;
+}
+
+const columns: Column<DataRow>[] = [
+  {
+    Header: ({ column }: HeaderProps<DataRow>) => (
+      <th data-column-name={column.id}>First name</th>
+    ),
+    Cell: ({ value }: CellProps<DataRow>) => <td>{value}</td>,
+    id: 'firstName',
+    accessor: 'firstName' as never,
+  },
+  {
+    Header: ({ column }: HeaderProps<DataRow>) => (
+      <th data-column-name={column.id}>City</th>
+    ),
+    Cell: ({ value }: CellProps<DataRow>) => <td>{value}</td>,
+    id: 'city',
+    accessor: 'city' as never,
+  },
+];
+
+const data: DataRow[] = [
+  { firstName: 'Michael', city: 'Paris' },
+  { firstName: 'Jordan', city: 'London' },
+];
+
+// Turns a render-phase throw, such as a Rules of Hooks violation, into a
+// readable assertion instead of an unhandled error.
+class RenderErrorBoundary extends Component<
+  RenderErrorBoundaryProps,
+  RenderErrorBoundaryState
+> {
+  state: RenderErrorBoundaryState = {
+    hasError: false,
+  };
+
+  static getDerivedStateFromError() {
+    return { hasError: true };
+  }
+
+  render() {
+    if (this.state.hasError) {
+      return <div data-test="render-error">Render error</div>;
+    }
+
+    return this.props.children;
+  }
+}
+
+const renderDataTable = (tableColumns: Column<DataRow>[]) => (
+  <ProviderWrapper>
+    <RenderErrorBoundary>
+      <DataTable<DataRow>
+        columns={tableColumns}
+        data={data}
+        rowCount={data.length}
+        serverPagination={false}
+        serverPaginationData={{}}
+        onServerPaginationChange={jest.fn()}
+        handleSortByChange={jest.fn()}
+        sortByFromParent={[]}
+        onSearchColChange={jest.fn()}
+        searchOptions={[]}
+        onFilteredRowsChange={jest.fn()}
+        sticky={false}
+      />
+    </RenderErrorBoundary>
+  </ProviderWrapper>
+);
+
+test('keeps the hook order stable when the columns disappear', () => {
+  const { rerender } = render(renderDataTable(columns));
+
+  expect(screen.getByText('Michael')).toBeInTheDocument();
+
+  rerender(renderDataTable([]));
+
+  expect(screen.queryByTestId('render-error')).not.toBeInTheDocument();

Review Comment:
   **Suggestion:** The error boundary renders `data-test="render-error"`, but 
this assertion queries for `data-testid="render-error"`. Consequently, it 
always returns null even when the boundary catches a render error, so the 
regression tests can pass while the DataTable is still broken. Use the same 
attribute in the boundary and assertion. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Minor ๐Ÿงน</summary>
   
   ```mdx
   - โš ๏ธ Both hook-order regression tests contain ineffective error-boundary 
assertions.
   - โš ๏ธ Future render failures can be misdiagnosed by these tests.
   - โš ๏ธ The reverse transition repeats the same attribute mismatch.
   ```
   </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=f079a4577c404ac2a8fb73e44515390b&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=f079a4577c404ac2a8fb73e44515390b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/plugins/plugin-chart-table/test/DataTable/DataTable.test.tsx
   **Line:** 114:114
   **Comment:**
        *Api Mismatch: The error boundary renders `data-test="render-error"`, 
but this assertion queries for `data-testid="render-error"`. Consequently, it 
always returns null even when the boundary catches a render error, so the 
regression tests can pass while the DataTable is still broken. Use the same 
attribute in the boundary and assertion.
   
   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%2F43150&comment_hash=0fa096465a7e24583c24370876fec50295743a7cb8dae3c87a316902ff6f4dbe&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43150&comment_hash=0fa096465a7e24583c24370876fec50295743a7cb8dae3c87a316902ff6f4dbe&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