sadpandajoe commented on code in PR #38776:
URL: https://github.com/apache/superset/pull/38776#discussion_r2968209976


##########
superset-frontend/src/SqlLab/components/QueryHistory/QueryHistory.test.tsx:
##########
@@ -81,7 +86,10 @@ const setup = (overrides = {}) => (
   <QueryHistory {...mockedProps} {...overrides} />
 );
 
-afterEach(() => fetchMock.clearHistory().removeRoutes());
+afterEach(() => {
+  fetchMock.clearHistory().removeRoutes();
+  cleanupExtensions();
+});

Review Comment:
   Fixed in e6efa58 — added `mockedIsFeatureEnabled.mockReset()` in `afterEach`.



##########
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();
+

Review Comment:
   Fixed in e6efa58 — added `expect(consoleErrorSpy).toHaveBeenCalled()` 
assertion.



##########
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:
   Fixed in e6efa58 — moved `consoleErrorSpy` to module scope with `afterEach` 
restore.



##########
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:
   Fixed in e6efa58 — changed to `queryByText` absence check to avoid 
duplicating the existing panel count 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:
   Fixed in e6efa58 — changed to `import type { ReactElement }`.



-- 
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]

Reply via email to