bito-code-review[bot] commented on code in PR #40931:
URL: https://github.com/apache/superset/pull/40931#discussion_r3504508132


##########
superset-frontend/packages/superset-ui-core/test/currency-format/symbolPosition.test.ts:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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 {
+  resolveSymbolPosition,
+  formatWithSymbolPosition,
+} from '@superset-ui/core';
+
+test('resolveSymbolPosition honors an explicit position regardless of locale', 
() => {
+  expect(resolveSymbolPosition('EUR', 'prefix', 'fr-FR')).toEqual('prefix');
+  expect(resolveSymbolPosition('USD', 'suffix', 'en-US')).toEqual('suffix');
+});
+
+test('resolveSymbolPosition derives the position from the locale when unset', 
() => {
+  // en-US places the symbol before the value for these currencies.
+  expect(resolveSymbolPosition('USD', undefined, 'en-US')).toEqual('prefix');
+  expect(resolveSymbolPosition('GBP', undefined, 'en-US')).toEqual('prefix');
+  expect(resolveSymbolPosition('EUR', undefined, 'en-US')).toEqual('prefix');
+
+  // Eurozone locales place the EUR symbol after the value.
+  expect(resolveSymbolPosition('EUR', undefined, 'fr-FR')).toEqual('suffix');
+  expect(resolveSymbolPosition('EUR', undefined, 'de-DE')).toEqual('suffix');
+});
+
+test('resolveSymbolPosition returns the same result on repeated calls 
(cached)', () => {
+  // The second call hits the memoized (locale, currencyCode) entry.
+  expect(resolveSymbolPosition('EUR', undefined, 'fr-FR')).toEqual('suffix');
+  expect(resolveSymbolPosition('EUR', undefined, 'fr-FR')).toEqual('suffix');
+});
+
+test('resolveSymbolPosition falls back to prefix for unknown currencies', () 
=> {
+  expect(resolveSymbolPosition('INVALID_CODE', undefined, 'en-US')).toEqual(
+    'prefix',
+  );
+  expect(resolveSymbolPosition(undefined, undefined, 'en-US')).toEqual(
+    'prefix',
+  );
+});
+
+test('resolveSymbolPosition falls back to prefix when locale parts lack a 
currency', () => {
+  const OrigNumberFormat = Intl.NumberFormat;
+  // formatToParts without a 'currency' part → currencyIndex is -1, so the
+  // position cannot be derived and the default prefix is returned. Use a
+  // locale/currency pair not exercised elsewhere so the memoization cache
+  // does not short-circuit this call.
+  Intl.NumberFormat = jest.fn().mockImplementation(() => ({
+    formatToParts: () => [{ type: 'integer', value: '1' }],
+  })) as unknown as typeof Intl.NumberFormat;
+
+  expect(resolveSymbolPosition('USD', undefined, 'zz-mock')).toEqual('prefix');
+
+  Intl.NumberFormat = OrigNumberFormat;
+});

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing finally block for cleanup</b></div>
   <div id="fix">
   
   The mock on line 62 replaces `Intl.NumberFormat` globally, but line 68 only 
restores it on the happy path. If `resolveSymbolPosition` throws for any reason 
(e.g., a regression), the global remains corrupted and subsequent tests in this 
file receive the mock instead of the real `Intl.NumberFormat`, potentially 
masking real bugs.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #e94dad</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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