Copilot commented on code in PR #35810:
URL: https://github.com/apache/superset/pull/35810#discussion_r2529048052


##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditor.test.utils.tsx:
##########
@@ -0,0 +1,86 @@
+/**
+ * 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 fetchMock from 'fetch-mock';
+import { render, waitFor } from 'spec/helpers/testing-library';
+import mockDatasource from 'spec/fixtures/mockDatasource';
+import type { DatasetObject } from 'src/features/datasets/types';
+import DatasourceEditor from '..';
+
+export interface DatasourceEditorProps {
+  datasource: DatasetObject;
+  addSuccessToast: () => void;
+  addDangerToast: () => void;
+  onChange: jest.Mock;
+  columnLabels?: Record<string, string>;
+  columnLabelTooltips?: Record<string, string>;
+}
+
+// Common setup for tests
+export const props: DatasourceEditorProps = {
+  datasource: mockDatasource['7__table'],
+  addSuccessToast: () => {},
+  addDangerToast: () => {},
+  onChange: jest.fn(),
+  columnLabels: {
+    state: 'State',
+  },
+  columnLabelTooltips: {
+    state: 'This is a tooltip for state',
+  },
+};
+
+export const DATASOURCE_ENDPOINT =
+  'glob:*/datasource/external_metadata_by_name/*';
+
+const routeProps = {
+  history: {},
+  location: {},
+  match: {},
+};
+
+export const asyncRender = (renderProps: DatasourceEditorProps) =>
+  waitFor(() =>
+    render(<DatasourceEditor {...renderProps} {...routeProps} />, {
+      useRedux: true,
+      initialState: { common: { currencies: ['USD', 'GBP', 'EUR'] } },
+      useRouter: true,
+    }),
+  );
+
+/**
+ * Setup common API mocks for DatasourceEditor tests.
+ * Mocks the 3 endpoints called on component mount to prevent test hangs and 
async warnings.

Review Comment:
   The JSDoc comment at lines 66-69 states this function mocks '3 endpoints 
called on component mount', but only 2 endpoints are actually mocked in the 
implementation (/api/v1/chart/ and /api/v1/database/). The 
/api/v1/dataset/related/owners endpoint mentioned in the comment (lines 81-85) 
appears to be additional. Either update the comment to say '2 main endpoints' 
or clarify the count.
   ```suggestion
    * Mocks the 2 main endpoints called on component mount, plus an additional 
related owners endpoint,
    * to prevent test hangs and async warnings.
   ```



##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.jsx:
##########
@@ -667,6 +667,8 @@ class DatasourceEditor extends PureComponent {
       usageChartsCount: 0,
     };
 
+    this.isComponentMounted = false;

Review Comment:
   [nitpick] The variable name `isComponentMounted` follows a boolean naming 
pattern but uses `is` prefix which is more commonly used for methods. Consider 
renaming to `isMounted` or `componentIsMounted` for consistency with the 
`isMountedRef` naming pattern used in DatasetUsageTab.



##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditorCurrency.test.tsx:
##########
@@ -33,160 +37,191 @@ const fastRender = (renderProps: typeof props) =>
     initialState: { common: { currencies: ['USD', 'GBP', 'EUR'] } },
   });
 
-// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from 
describe blocks
-describe('DatasourceEditor Currency Tests', () => {
-  beforeEach(() => {
-    fetchMock.get(DATASOURCE_ENDPOINT, [], { overwriteRoutes: true });
-  });
+// Factory function for currency props - returns fresh copy to prevent test 
pollution
+const createPropsWithCurrency = () => ({
+  ...props,
+  datasource: {
+    ...props.datasource,
+    metrics: [
+      {
+        ...props.datasource.metrics[0],
+        currency: { symbol: 'USD', symbolPosition: 'prefix' },
+      },
+      ...props.datasource.metrics.slice(1).map(m => ({ ...m })),

Review Comment:
   The factory function creates shallow copies of metrics using `map(m => ({ 
...m }))`, but this only creates shallow copies. If metric objects contain 
nested objects (like the currency object being tested), mutations could still 
leak between tests. Consider using deep cloning or ensuring the currency object 
is also properly copied.



##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.test.tsx:
##########
@@ -181,6 +181,8 @@ beforeAll(() => {
 });
 
 afterEach(() => {
+  jest.runOnlyPendingTimers();

Review Comment:
   Running `jest.runOnlyPendingTimers()` before `jest.useRealTimers()` in the 
afterEach hook may cause issues if some tests don't use fake timers. Consider 
wrapping this in a try-catch or checking if fake timers are active before 
running pending timers to avoid potential test failures.
   ```suggestion
     try {
       jest.runOnlyPendingTimers();
     } catch (e) {
       // Ignore if fake timers are not in use
     }
   ```



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