Copilot commented on code in PR #38776: URL: https://github.com/apache/superset/pull/38776#discussion_r2967611983
########## superset-frontend/src/SqlLab/extensionContracts.test.tsx: ########## @@ -0,0 +1,92 @@ +/** + * 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 React from 'react'; +import { render, screen } from 'spec/helpers/testing-library'; +import userEvent from '@testing-library/user-event'; +import { views } from 'src/core'; +import PanelToolbar from 'src/components/PanelToolbar'; +import StatusBar from 'src/SqlLab/components/StatusBar'; +import { ViewLocations } from 'src/SqlLab/contributions'; +import { + registerTestView, + registerToolbarAction, + cleanupExtensions, +} from 'src/SqlLab/test-utils/extensionTestHelpers'; + +afterEach(cleanupExtensions); + +test('disposing a registered view removes it from rendering', () => { + const disposable = views.registerView( + { id: 'dispose-test', name: 'Dispose Test' }, + ViewLocations.sqllab.statusBar, + () => React.createElement('div', null, 'Disposable Content'), + ); + + const { rerender } = render(<StatusBar />); + expect(screen.getByText('Disposable Content')).toBeInTheDocument(); + + disposable.dispose(); + rerender(<StatusBar />); + expect(screen.queryByText('Disposable Content')).not.toBeInTheDocument(); +}); + +test('extension throwing during render does not crash host', () => { + const consoleError = jest + .spyOn(console, 'error') + .mockImplementation(() => {}); + + const ThrowingComponent = () => { + throw new Error('Extension error'); + }; + + registerTestView( + ViewLocations.sqllab.statusBar, + 'throwing-ext', + 'Throwing', + () => React.createElement(ThrowingComponent), + ); + registerTestView( + ViewLocations.sqllab.statusBar, + 'healthy-ext', + 'Healthy', + () => React.createElement('div', null, 'Healthy Content'), + ); + + render(<StatusBar />); + + // Healthy extension still renders despite the throwing extension + expect(screen.getByText('Healthy Content')).toBeInTheDocument(); + + consoleError.mockRestore(); Review Comment: `console.error` is mocked but only restored at the end of the test. If the test fails before reaching the restore call, the mock can leak and affect subsequent tests. Wrap the body in try/finally (or use an afterEach restore) to guarantee `mockRestore()` runs. ```suggestion try { const ThrowingComponent = () => { throw new Error('Extension error'); }; registerTestView( ViewLocations.sqllab.statusBar, 'throwing-ext', 'Throwing', () => React.createElement(ThrowingComponent), ); registerTestView( ViewLocations.sqllab.statusBar, 'healthy-ext', 'Healthy', () => React.createElement('div', null, 'Healthy Content'), ); render(<StatusBar />); // Healthy extension still renders despite the throwing extension expect(screen.getByText('Healthy Content')).toBeInTheDocument(); } finally { consoleError.mockRestore(); } ``` ########## superset-frontend/src/SqlLab/extensionContracts.test.tsx: ########## @@ -0,0 +1,92 @@ +/** + * 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 React from 'react'; +import { render, screen } from 'spec/helpers/testing-library'; +import userEvent from '@testing-library/user-event'; +import { views } from 'src/core'; +import PanelToolbar from 'src/components/PanelToolbar'; +import StatusBar from 'src/SqlLab/components/StatusBar'; +import { ViewLocations } from 'src/SqlLab/contributions'; +import { + registerTestView, + registerToolbarAction, + cleanupExtensions, +} from 'src/SqlLab/test-utils/extensionTestHelpers'; + +afterEach(cleanupExtensions); + +test('disposing a registered view removes it from rendering', () => { + const disposable = views.registerView( + { id: 'dispose-test', name: 'Dispose Test' }, + ViewLocations.sqllab.statusBar, Review Comment: This test registers a view via `views.registerView` but doesn’t use the shared helper that tracks disposables. If an assertion throws before `dispose()` runs, the registration can leak into later tests. Consider using `registerTestView` (and/or wrapping `dispose()` in a try/finally) so cleanup is guaranteed. ```suggestion const disposable = registerTestView( ViewLocations.sqllab.statusBar, 'dispose-test', 'Dispose Test', ``` ########## superset-frontend/src/SqlLab/test-utils/extensionTestHelpers.ts: ########## @@ -0,0 +1,70 @@ +/** + * 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 { ReactElement } from 'react'; Review Comment: This import is type-only; in this codebase tests commonly use `import type { ... }` for React types. Updating this to a type import keeps consistency and avoids accidental runtime imports under stricter TS/ESLint settings. ```suggestion import type { ReactElement } from 'react'; ``` ########## superset-frontend/src/SqlLab/components/AppLayout/AppLayout.test.tsx: ########## @@ -94,10 +99,19 @@ test('calls setWidth on sidebar resize when not hidden', async () => { await waitFor(() => expect(setWidth).toHaveBeenCalled()); }); +test('right sidebar is hidden when no extensions registered', () => { + const { getAllByTestId } = render(<AppLayout {...defaultProps} />, { + useRedux: true, + initialState, + }); + expect(getAllByTestId('mock-panel')).toHaveLength(2); Review Comment: This test duplicates the assertion already covered by `test('renders two panels', ...)` above (both assert there are 2 panels when no right-sidebar contributions exist). Consider removing one, or making this one assert something more specific to the right-sidebar contract (e.g., that no right-sidebar extension content/container is rendered). ```suggestion const { queryByText } = render(<AppLayout {...defaultProps} />, { useRedux: true, initialState, }); expect(queryByText('Right Sidebar Content')).not.toBeInTheDocument(); ``` -- 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]
