bito-code-review[bot] commented on code in PR #38374: URL: https://github.com/apache/superset/pull/38374#discussion_r2881279282
########## 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-testid="scatter-overlay" data-opacity={props.globalOpacity} /> + ); + return { __esModule: true, default: MockOverlay }; +}); Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Test mock attribute mismatch</b></div> <div id="fix"> The mock uses 'data-test' but the test calls getByTestId('scatter-overlay'), which expects 'data-testid'. This will cause the test to fail at runtime. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion jest.mock('../src/ScatterPlotGlowOverlay', () => { const MockOverlay = (props: Record<string, unknown>) => ( <div data-testid="scatter-overlay" data-opacity={props.globalOpacity} /> ); return { __esModule: true, default: MockOverlay }; }); ```` </div> </details> </div> <small><i>Code Review Run #d84af0</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset-frontend/plugins/legacy-plugin-chart-map-box/test/transformProps.test.ts: ########## @@ -0,0 +1,116 @@ +/* + * 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 { ChartProps } from '@superset-ui/core'; +import { supersetTheme } from '@apache-superset/core/ui'; + +jest.mock('supercluster', () => { + const MockSupercluster = jest.fn().mockImplementation(() => ({ + load: jest.fn(), + getClusters: jest.fn().mockReturnValue([]), + })); + return { __esModule: true, default: MockSupercluster }; +}); + +// Import after mocking supercluster to avoid ESM parse error +// eslint-disable-next-line import/first +import transformProps from '../src/transformProps'; + +const baseFormData = { + clusteringRadius: 60, + globalOpacity: 0.8, + mapboxColor: 'rgb(0, 139, 139)', + mapboxStyle: 'mapbox://styles/mapbox/light-v9', + pandasAggfunc: 'sum', + pointRadiusUnit: 'Pixels', + renderWhileDragging: true, + viewportLongitude: -73.935242, + viewportLatitude: 40.73061, + viewportZoom: 9, +}; + +const baseQueriesData = [ + { + data: { + bounds: [ + [-74.0, 40.7], + [-73.9, 40.8], + ] as [[number, number], [number, number]], + geoJSON: { features: [] }, + hasCustomMetric: false, + mapboxApiKey: 'test-api-key', + }, + }, +]; + +function createChartProps(overrides: Record<string, unknown> = {}) { + return new ChartProps({ + formData: { ...baseFormData, ...overrides }, + width: 800, + height: 600, + queriesData: baseQueriesData, + theme: supersetTheme, + }); +} + +test('extracts globalOpacity from formData', () => { Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Incomplete test coverage for error handling</b></div> <div id="fix"> The test suite does not cover the color validation error handling in transformProps, where invalid colors should trigger onError and return an empty object. This could allow bugs in input validation to go undetected. </div> </div> <small><i>Code Review Run #d84af0</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- 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]
