codeant-ai-for-open-source[bot] commented on code in PR #37902: URL: https://github.com/apache/superset/pull/37902#discussion_r2870625516
########## superset-frontend/src/explore/components/controls/SpatialControl.test.tsx: ########## @@ -0,0 +1,178 @@ +/** + * 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 { render, screen, waitFor } from 'spec/helpers/testing-library'; +import userEvent from '@testing-library/user-event'; +import SpatialControl from 'src/explore/components/controls/SpatialControl'; + +jest.mock('src/explore/components/controls/SelectControl', () => ({ + __esModule: true, + default: ({ + name, + value, + ariaLabel, + }: { + name: string; + value: string; + ariaLabel: string; + }) => ( + <div data-test={`select-${name}`} aria-label={ariaLabel}> + {value} + </div> + ), +})); + +jest.mock('src/explore/components/ControlHeader', () => ({ + __esModule: true, + default: () => <div data-test="control-header" />, Review Comment: **Suggestion:** The test `renders ControlHeader` uses `screen.getByTestId('control-header')`, but the mocked `ControlHeader` currently renders a `div` with `data-test="control-header"` instead of `data-testid`, so the query will never find the element and the test will always fail; update the mock to use `data-testid` to align with Testing Library's test ID convention. [logic error] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ❌ SpatialControl "renders ControlHeader" unit test always fails. - ⚠️ Frontend Jest suite may fail, blocking CI merges. - ⚠️ Reduces confidence in SpatialControl hook-based refactor coverage. ``` </details> ```suggestion default: () => <div data-testid="control-header" />, ``` <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Run the frontend unit tests that include `SpatialControl.test.tsx`, for example via the project's Jest test script (this file is at `superset-frontend/src/explore/components/controls/SpatialControl.test.tsx`). 2. When Jest loads this test file, the mock at lines 40–43 replaces `src/explore/components/ControlHeader` with a component that renders `<div data-test="control-header" />` (no `data-testid` attribute). 3. The test `renders ControlHeader` at lines 155–160 renders `<SpatialControl />` (which uses `ControlHeader`) and then calls `screen.getByTestId('control-header')`; Testing Library (via `spec/helpers/testing-library` and consistent with other tests like `MatrixifyDimensionControl.test.tsx:53` which use `data-testid="control-header"`) looks specifically for a `data-testid="control-header"` attribute. 4. Because the mocked `ControlHeader` only renders `data-test="control-header"` and no element has `data-testid="control-header"`, `screen.getByTestId('control-header')` throws an error, causing the `renders ControlHeader` test – and thus the Jest run – to fail every time. ``` </details> <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/controls/SpatialControl.test.tsx **Line:** 42:42 **Comment:** *Logic Error: The test `renders ControlHeader` uses `screen.getByTestId('control-header')`, but the mocked `ControlHeader` currently renders a `div` with `data-test="control-header"` instead of `data-testid`, so the query will never find the element and the test will always fail; update the mock to use `data-testid` to align with Testing Library's test ID convention. 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> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37902&comment_hash=c99b3fafa26b99712db438295836935603410cb0fe7cba78e9c1e2d61d750a23&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37902&comment_hash=c99b3fafa26b99712db438295836935603410cb0fe7cba78e9c1e2d61d750a23&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]
