codeant-ai-for-open-source[bot] commented on code in PR #37284: URL: https://github.com/apache/superset/pull/37284#discussion_r2722743905
########## superset-frontend/src/components/Chart/ChartContextMenu/ChartContextMenu.test.tsx: ########## @@ -0,0 +1,142 @@ +/** + * 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 { useRef } from 'react'; +import { FeatureFlag, VizType } from '@superset-ui/core'; +import { render, screen, waitFor } from 'spec/helpers/testing-library'; +import userEvent from '@testing-library/user-event'; +import mockState from 'spec/fixtures/mockState'; +import { sliceId } from 'spec/fixtures/mockChartQueries'; +import { cachedSupersetGet } from 'src/utils/cachedSupersetGet'; +import ChartContextMenu, { + ChartContextMenuRef, + ContextMenuItem, +} from './ChartContextMenu'; + +jest.mock('src/utils/cachedSupersetGet'); + +const mockCachedSupersetGet = cachedSupersetGet as jest.MockedFunction< + typeof cachedSupersetGet +>; + +// @ts-ignore +global.featureFlags = { + [FeatureFlag.DrillToDetail]: true, + [FeatureFlag.DrillBy]: true, +}; + +const defaultFormData = { + datasource: '1__table', + viz_type: VizType.Pie, +}; + +const TestWrapper = ({ onClose = jest.fn() }: { onClose?: jest.Mock }) => { + const contextMenuRef = useRef<ChartContextMenuRef>(null); + + return ( + <> + <button + onClick={() => contextMenuRef.current?.open(100, 100, {})} + data-test="open-context-menu" Review Comment: **Suggestion:** The test queries use `getByTestId('open-context-menu')` but the button in `TestWrapper` sets `data-test="open-context-menu"` (typo); RTL's `getByTestId` looks for `data-testid`. Change the attribute to `data-testid` so the test can find and interact with the button. [possible bug] <details> <summary><b>Severity Level:</b> Critical 🚨</summary> ```mdx - ❌ Unit test file fails blocking CI runs. - ⚠️ Developers see failing local tests when running this spec. ``` </details> ```suggestion data-testid="open-context-menu" ``` <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Run the unit test file `superset-frontend/src/components/Chart/ChartContextMenu/ChartContextMenu.test.tsx`. 2. Test at line 108 calls `screen.getByTestId('open-context-menu')` (file: ChartContextMenu.test.tsx:108) to locate the open button. 3. The rendered DOM (from TestWrapper at ChartContextMenu.test.tsx:53-58) contains a button with attribute `data-test="open-context-menu"` (line 55) not `data-testid`. 4. RTL's `getByTestId` will not find an element with `data-testid`, causing the test to throw "Unable to find an element by the test id: open-context-menu" and fail immediately. 5. Observation: current file uses `data-test` (ChartContextMenu.test.tsx:55) while assertions expect `data-testid` (ChartContextMenu.test.tsx:108 and 129), so updating to `data-testid` aligns DOM and queries and resolves the deterministic failure. ``` </details> <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/src/components/Chart/ChartContextMenu/ChartContextMenu.test.tsx **Line:** 55:55 **Comment:** *Possible Bug: The test queries use `getByTestId('open-context-menu')` but the button in `TestWrapper` sets `data-test="open-context-menu"` (typo); RTL's `getByTestId` looks for `data-testid`. Change the attribute to `data-testid` so the test can find and interact with the button. 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]
