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


##########
superset-frontend/src/utils/assetUrl.test.ts:
##########
@@ -0,0 +1,50 @@
+/**
+ * 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 * as getBootstrapData from 'src/utils/getBootstrapData';
+import { assetUrl, ensureStaticPrefix } from './assetUrl';
+
+const staticAssetsPrefixMock = jest.spyOn(
+  getBootstrapData,
+  'staticAssetsPrefix',
+);
+const resourcePath = '/endpoint/img.png';
+const absoluteResourcePath = `https://cdn.domain.com/static${resourcePath}`;
+
+beforeEach(() => {
+  // Clear app root
+  staticAssetsPrefixMock.mockReturnValue('');
+});
+
+describe('assetUrl should prepend static asset prefix', () => {
+  it.each(['', '/myapp'])("'%s' for relative path", app_root => {
+    staticAssetsPrefixMock.mockReturnValue(app_root);
+    expect(assetUrl(resourcePath)).toBe(`${app_root}${resourcePath}`);
+    expect(assetUrl(absoluteResourcePath)).toBe(
+      `${app_root}/${absoluteResourcePath}`,
+    );

Review Comment:
   The test for `assetUrl` with an absolute URL (line 38-40) expects it to 
prepend the app root and a slash, which would produce invalid URLs like 
`/myapp/https://cdn.domain.com/static/endpoint/img.png`. The `assetUrl` 
function is designed for relative paths only. This test case should either be 
removed or moved to a separate test that validates `assetUrl` should not be 
used with absolute URLs.
   ```suggestion
   
   ```



##########
superset-frontend/src/utils/assetUrl.test.ts:
##########
@@ -0,0 +1,50 @@
+/**
+ * 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 * as getBootstrapData from 'src/utils/getBootstrapData';
+import { assetUrl, ensureStaticPrefix } from './assetUrl';
+
+const staticAssetsPrefixMock = jest.spyOn(
+  getBootstrapData,
+  'staticAssetsPrefix',
+);
+const resourcePath = '/endpoint/img.png';
+const absoluteResourcePath = `https://cdn.domain.com/static${resourcePath}`;
+
+beforeEach(() => {
+  // Clear app root

Review Comment:
   The comment says "Clear app root" but the code is actually clearing the 
static assets prefix mock. The comment should be updated to "Clear static 
assets prefix" to accurately reflect what the code is doing.
   ```suggestion
     // Clear static assets prefix
   ```



##########
superset-frontend/src/features/home/Menu.test.tsx:
##########
@@ -247,6 +252,8 @@ fetchMock.get(
 beforeEach(() => {
   // setup a DOM element as a render target
   useSelectorMock.mockClear();
+  // By default use empty app root

Review Comment:
   The comment says "By default use empty app root" but the code is actually 
setting the static assets prefix mock to an empty string. The comment should be 
updated to "By default use empty static assets prefix" to accurately reflect 
what the code is doing.
   ```suggestion
     // By default use empty static assets prefix
   ```



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