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


##########
superset-frontend/src/SqlLab/components/QueryStatusBar/QueryStatusBar.test.tsx:
##########
@@ -0,0 +1,161 @@
+/**
+ * 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 { isValidElement } from 'react';
+import { render, screen } from 'spec/helpers/testing-library';
+import { QueryState, type QueryResponse } from '@superset-ui/core';
+import QueryStatusBar from '.';
+
+jest.mock('../QueryStateLabel', () => ({
+  __esModule: true,
+  default: ({ query }: { query: { state: QueryState } }) => (
+    <div data-test="query-state-label">{query.state}</div>
+  ),
+}));
+
+const createMockQuery = (
+  overrides: Partial<QueryResponse> = {},
+): QueryResponse =>
+  ({
+    id: 'test-query-id',
+    dbId: 1,
+    sql: 'SELECT * FROM test',
+    sqlEditorId: 'test-editor',
+    tab: 'Test Tab',
+    ctas: false,
+    cached: false,
+    progress: 0,
+    startDttm: Date.now() - 1000,
+    endDttm: undefined,
+    state: QueryState.Running,
+    tempSchema: null,
+    tempTable: null,
+    userId: 1,
+    executedSql: null,
+    rows: 0,
+    queryLimit: 100,
+    catalog: null,
+    schema: 'test_schema',
+    errorMessage: null,
+    extra: {},
+    results: undefined,
+    ...overrides,
+  }) as QueryResponse;
+
+test('is valid element', () => {
+  const query = createMockQuery();
+  expect(isValidElement(<QueryStatusBar query={query} />)).toBe(true);
+});
+
+test('renders query state label', () => {
+  const query = createMockQuery({ state: QueryState.Running });
+  render(<QueryStatusBar query={query} />);
+  expect(screen.getByTestId('query-state-label')).toBeInTheDocument();
+  expect(screen.getByText('Query State:')).toBeInTheDocument();
+});
+
+test('renders elapsed time section', () => {
+  const query = createMockQuery({ state: QueryState.Running });
+  render(<QueryStatusBar query={query} />);
+  expect(screen.getByText('Elapsed:')).toBeInTheDocument();
+});
+
+test('renders steps for running query', () => {
+  const query = createMockQuery({ state: QueryState.Running, progress: 50 });
+  render(<QueryStatusBar query={query} />);
+  expect(screen.getByText('Validate query')).toBeInTheDocument();
+  expect(screen.getByText('Connect to engine')).toBeInTheDocument();
+  expect(screen.getByText('Running')).toBeInTheDocument();
+  expect(screen.getByText('Download to client')).toBeInTheDocument();
+  expect(screen.getByText('Finish')).toBeInTheDocument();
+});
+
+test('renders steps for pending query', () => {
+  const query = createMockQuery({ state: QueryState.Pending });
+  render(<QueryStatusBar query={query} />);
+  expect(screen.getByText('Validate query')).toBeInTheDocument();
+});
+
+test('returns null when query is successful with results', () => {
+  const query = createMockQuery({
+    state: QueryState.Success,
+    results: {
+      displayLimitReached: false,
+      columns: [],
+      selected_columns: [],
+      expanded_columns: [],
+      data: [],
+      query: { limit: 100 },
+    },
+  });
+  const { container } = render(<QueryStatusBar query={query} />);
+  expect(container.firstChild).toBeEmptyDOMElement();

Review Comment:
   **Suggestion:** The test asserts 
`expect(container.firstChild).toBeEmptyDOMElement()` when the component 
intentionally returns `null` for successful queries with results; 
`toBeEmptyDOMElement` expects an Element and will throw if `firstChild` is 
`null`. Replace the assertion with `toBeNull()` to correctly assert the 
component rendered nothing. [logic error]
   
   **Severity Level:** Minor ⚠️
   ```suggestion
     expect(container.firstChild).toBeNull();
   ```
   <details>
   <summary><b>Why it matters? ⭐ </b></summary>
   
   The intent is to assert that the component rendered nothing. 
container.firstChild can be null if the component returns null,
   and toBeEmptyDOMElement expects an Element (it will throw/assert incorrectly 
when given null). Replacing with toBeNull()
   correctly expresses the intent and avoids false failures/exceptions in the 
test.
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/SqlLab/components/QueryStatusBar/QueryStatusBar.test.tsx
   **Line:** 107:107
   **Comment:**
        *Logic Error: The test asserts 
`expect(container.firstChild).toBeEmptyDOMElement()` when the component 
intentionally returns `null` for successful queries with results; 
`toBeEmptyDOMElement` expects an Element and will throw if `firstChild` is 
`null`. Replace the assertion with `toBeNull()` to correctly assert the 
component rendered nothing.
   
   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.
   ```
   </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: [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