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


##########
superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts:
##########
@@ -319,8 +319,11 @@ describe('EchartsTimeseries transformProps', () => {
     expect(formulaSeries).toBeDefined();
     expect(formulaSeries?.data).toBeDefined();
     expect(Array.isArray(formulaSeries?.data)).toBe(true);
-    expect((formulaSeries!.data as unknown[]).length).toBeGreaterThan(0);
-    const firstDataPoint = (formulaSeries!.data as [number, number][])[0];
+    const series = formulaSeries as SeriesOption;
+    const data = series.data as [number, number][];
+    expect(Array.isArray(data)).toBe(true);
+    expect(data.length).toBeGreaterThan(0);
+    const firstDataPoint = data[0];

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Inconsistent test coverage</b></div>
   <div id="fix">
   
   The refactored code at lines 405-407 introduces intermediate variables for 
type safety, but differs from the parallel pattern at lines 322-326 by omitting 
the defensive length check. Accessing `data[0]` without verifying length could 
throw an error if data is empty or undefined. Apply the same 
`expect(data.length).toBeGreaterThan(0);` assertion here.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #a234cf</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



##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts:
##########
@@ -69,6 +69,31 @@ import {
   TIMESERIES_CONSTANTS,
 } from '../constants';
 
+function parseTimeShiftToMs(timeShift?: string | null): number {
+  if (!timeShift) return 0;
+
+  const match = timeShift
+    .trim()
+    
.match(/^(-?\d+(?:\.\d+)?)\s*(second|minute|hour|day|week|month|year)s?$/i);
+
+  if (!match) return 0;
+
+  const value = Number(match[1]);
+  const unit = match[2].toLowerCase();
+
+  const MS: Record<string, number> = {
+    second: 1000,
+    minute: 60 * 1000,
+    hour: 60 * 60 * 1000,
+    day: 24 * 60 * 60 * 1000,
+    week: 7 * 24 * 60 * 60 * 1000,
+    month: 30 * 24 * 60 * 60 * 1000,
+    year: 365 * 24 * 60 * 60 * 1000,
+  };
+
+  return value * (MS[unit] ?? 0);
+}

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing unit tests for time_shift</b></div>
   <div id="fix">
   
   The new `parseTimeShiftToMs` function lacks unit tests. Tests should verify 
parsing of valid formats (positive/negative values, singular/plural units), 
invalid inputs returning 0, and common time units 
(second/minute/hour/day/week/month/year).
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #2c9153</i></small>
   </div><div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing unit tests for new function</b></div>
   <div id="fix">
   
   No tests exist for the new `parseTimeShiftToMs` function (lines 72-95) or 
its usage in `transformTimeseriesAnnotation`. BITO.md rule [11730] requires 
comprehensive unit tests covering success paths and edge cases for new 
functionality.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #a234cf</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