codeant-ai-for-open-source[bot] commented on code in PR #38374: URL: https://github.com/apache/superset/pull/38374#discussion_r2881250987
########## superset-frontend/plugins/legacy-plugin-chart-map-box/test/MapBox.test.tsx: ########## @@ -0,0 +1,140 @@ +/* + * 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 } from '@testing-library/react'; +import MapBox from '../src/MapBox'; + +// Capture the most recent viewport props passed to MapGL +let lastMapGLProps: Record<string, unknown> = {}; + +jest.mock('react-map-gl', () => { + const MockMapGL = (props: Record<string, unknown>) => { + lastMapGLProps = props; + return <div data-testid="map-gl">{props.children as React.ReactNode}</div>; + }; + return { __esModule: true, default: MockMapGL }; +}); + +jest.mock('@math.gl/web-mercator', () => ({ + WebMercatorViewport: jest.fn().mockImplementation(() => ({ + fitBounds: jest.fn().mockReturnValue({ + latitude: 40.75, + longitude: -73.95, + zoom: 10, + }), + })), +})); + +jest.mock('../src/ScatterPlotGlowOverlay', () => { + const MockOverlay = (props: Record<string, unknown>) => ( + <div data-test="scatter-overlay" data-opacity={props.globalOpacity} /> Review Comment: **Suggestion:** The test mock for the overlay component sets a `data-test` attribute, but the test queries with `getByTestId`, which looks for `data-testid`; this mismatch will cause the test to fail because the element cannot be found. [logic error] <details> <summary><b>Severity Level:</b> Critical 🚨</summary> ```mdx - ❌ MapBox test suite fails on `passes globalOpacity` test. - ❌ CI for frontend tests can be consistently red. ``` </details> ```suggestion <div data-testid="scatter-overlay" data-opacity={props.globalOpacity} /> ``` <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Run the Jest test suite including `superset-frontend/plugins/legacy-plugin-chart-map-box/test/MapBox.test.tsx`. 2. Jest applies the mock at lines 44-49, rendering `MockOverlay` as `<div data-test="scatter-overlay" ... />` (no `data-testid` attribute). 3. The test `passes globalOpacity to ScatterPlotGlowOverlay` at lines 134-140 renders `<MapBox {...defaultProps} globalOpacity={0.5} />`, which in turn renders the mocked overlay. 4. The test calls `getByTestId('scatter-overlay')`, which queries for `data-testid="scatter-overlay"`; since the element only has `data-test`, the query throws and the test fails. ``` </details> <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/plugins/legacy-plugin-chart-map-box/test/MapBox.test.tsx **Line:** 46:46 **Comment:** *Logic Error: The test mock for the overlay component sets a `data-test` attribute, but the test queries with `getByTestId`, which looks for `data-testid`; this mismatch will cause the test to fail because the element cannot be found. 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%2F38374&comment_hash=4eaa2f244288109cbd76ff7ef33d08376783be7de50268fdca7539e8a714e63a&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38374&comment_hash=4eaa2f244288109cbd76ff7ef33d08376783be7de50268fdca7539e8a714e63a&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]
