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


##########
superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts:
##########
@@ -633,4 +636,133 @@ describe('Does transformProps transform series 
correctly', () => {
       'foo2, bar2': ['foo2', 'bar2'],
     });
   });
+
+  describe('should add the correct time formatter for the xAxis', () => {
+    const getXAxisFormatter = (timeGrainSqla: TimeGranularity) => {
+      const updatedChartPropsConfig = {
+        ...chartPropsConfig,
+        formData: {
+          ...chartPropsConfig.formData,
+          time_grain_sqla: timeGrainSqla,
+          xAxisTimeFormat: '%Y-%m-%d',
+        },
+        queriesData: [
+          {
+            data: chartPropsConfig.queriesData[0].data,
+            colnames: ['San Francisco', 'New York', '__timestamp'],
+            coltypes: [
+              GenericDataType.String,
+              GenericDataType.String,
+              GenericDataType.Temporal,
+            ],
+          },
+        ],
+      };
+      const { echartOptions } = transformProps(
+        new ChartProps(updatedChartPropsConfig) as EchartsTimeseriesChartProps,
+      );
+      const xAxis = echartOptions.xAxis as {
+        axisLabel: { formatter: TimeFormatter };
+      };
+      return xAxis.axisLabel.formatter;
+    };
+
+    it('should work for days', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.DAY);
+      expect(formatter(1610000000000)).toEqual(
+        expect.stringMatching('2021-01-07'),
+      );
+    });
+
+    it('should work for weeks', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.WEEK);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(
+        expect.stringMatching('2021-01-07 — 2021-01-13'),
+      );
+    });
+
+    it('should work for months', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.MONTH);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(expect.stringContaining('Jan'));
+      
expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+    });
+
+    it('should work for quarters', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.QUARTER);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(expect.stringContaining('Q1'));
+      
expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+    });
+
+    it('should work for years', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.QUARTER);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(expect.stringMatching('2021'));
+    });
+  });
+
+  describe('should add the correct time formatter for the tooltip', () => {
+    const getTooltipFormatter = (timeGrainSqla: TimeGranularity) => {
+      const updatedChartPropsConfig = {
+        ...chartPropsConfig,
+        formData: {
+          ...chartPropsConfig.formData,
+          time_grain_sqla: timeGrainSqla,
+          tooltipTimeFormat: '%Y-%m-%d',
+        },
+        queriesData: [
+          {
+            data: chartPropsConfig.queriesData[0].data,
+            colnames: ['San Francisco', 'New York', '__timestamp'],
+            coltypes: [
+              GenericDataType.String,
+              GenericDataType.String,
+              GenericDataType.Temporal,
+            ],
+          },
+        ],
+      };
+
+      return transformProps(
+        new ChartProps(updatedChartPropsConfig) as EchartsTimeseriesChartProps,
+      ).xValueFormatter;
+    };
+
+    it('should work for days', () => {
+      const formatter = getTooltipFormatter(TimeGranularity.DAY);
+      expect(formatter(1610000000000)).toEqual(
+        expect.stringMatching('2021-01-07'),
+      );
+    });
+
+    it('should work for weeks', () => {
+      const formatter = getTooltipFormatter(TimeGranularity.WEEK);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(
+        expect.stringMatching('2021-01-07 — 2021-01-13'),
+      );
+    });
+
+    it('should work for months', () => {
+      const formatter = getTooltipFormatter(TimeGranularity.MONTH);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(expect.stringContaining('Jan'));
+      
expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+    });
+
+    it('should work for quarters', () => {
+      const formatter = getTooltipFormatter(TimeGranularity.QUARTER);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(expect.stringContaining('Q1'));
+      
expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+    });
+
+    it('should work for years', () => {
+      const formatter = getTooltipFormatter(TimeGranularity.QUARTER);

Review Comment:
   In the 'should work for years' tooltip test, you’re passing 
TimeGranularity.QUARTER. It should be TimeGranularity.YEAR to test the year 
formatter.
   ```suggestion
         const formatter = getTooltipFormatter(TimeGranularity.YEAR);
   ```



##########
superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts:
##########
@@ -162,3 +169,154 @@ it('should transform chart props for viz', () => {
     }),
   );
 });
+
+describe('should add the correct time formatter for the xAxis', () => {
+  const getXAxisFormatter = (timeGrainSqla: TimeGranularity) => {
+    const updatedChartPropsConfig = {
+      ...chartPropsConfig,
+      formData: {
+        ...chartPropsConfig.formData,
+        time_grain_sqla: timeGrainSqla,
+        xAxisTimeFormat: '%Y-%m-%d',
+      },
+      queriesData: [
+        {
+          data: chartPropsConfig.queriesData[0].data,
+          label_map: chartPropsConfig.queriesData[0].label_map,
+          colnames: ['Boy', 'Girl', 'ds'],
+          coltypes: [
+            GenericDataType.String,
+            GenericDataType.String,
+            GenericDataType.Temporal,
+          ],
+        },
+        {
+          data: chartPropsConfig.queriesData[1].data,
+          label_map: chartPropsConfig.queriesData[1].label_map,
+          colnames: ['Boy', 'Girl', 'ds'],
+          coltypes: [
+            GenericDataType.String,
+            GenericDataType.String,
+            GenericDataType.Temporal,
+          ],
+        },
+      ],
+    };
+    const { echartOptions } = transformProps(
+      new ChartProps(updatedChartPropsConfig) as EchartsMixedTimeseriesProps,
+    );
+    const xAxis = echartOptions.xAxis as {
+      axisLabel: { formatter: TimeFormatter };
+    };
+    return xAxis.axisLabel.formatter;
+  };
+
+  it('should work for days', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.DAY);
+    expect(formatter(1610000000000)).toEqual(
+      expect.stringMatching('2021-01-07'),
+    );
+  });
+
+  it('should work for weeks', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.WEEK);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(
+      expect.stringMatching('2021-01-07 — 2021-01-13'),
+    );
+  });
+
+  it('should work for months', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.MONTH);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('Jan'));
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+  });
+
+  it('should work for quarters', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.QUARTER);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('Q1'));
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+  });
+
+  it('should work for years', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.QUARTER);

Review Comment:
   In the 'should work for years' xAxis test, you’re using 
TimeGranularity.QUARTER. Update to TimeGranularity.YEAR to cover the year case.
   ```suggestion
       const formatter = getXAxisFormatter(TimeGranularity.YEAR);
   ```



##########
superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts:
##########
@@ -162,3 +169,154 @@ it('should transform chart props for viz', () => {
     }),
   );
 });
+
+describe('should add the correct time formatter for the xAxis', () => {
+  const getXAxisFormatter = (timeGrainSqla: TimeGranularity) => {
+    const updatedChartPropsConfig = {
+      ...chartPropsConfig,
+      formData: {
+        ...chartPropsConfig.formData,
+        time_grain_sqla: timeGrainSqla,
+        xAxisTimeFormat: '%Y-%m-%d',
+      },
+      queriesData: [
+        {
+          data: chartPropsConfig.queriesData[0].data,
+          label_map: chartPropsConfig.queriesData[0].label_map,
+          colnames: ['Boy', 'Girl', 'ds'],
+          coltypes: [
+            GenericDataType.String,
+            GenericDataType.String,
+            GenericDataType.Temporal,
+          ],
+        },
+        {
+          data: chartPropsConfig.queriesData[1].data,
+          label_map: chartPropsConfig.queriesData[1].label_map,
+          colnames: ['Boy', 'Girl', 'ds'],
+          coltypes: [
+            GenericDataType.String,
+            GenericDataType.String,
+            GenericDataType.Temporal,
+          ],
+        },
+      ],
+    };
+    const { echartOptions } = transformProps(
+      new ChartProps(updatedChartPropsConfig) as EchartsMixedTimeseriesProps,
+    );
+    const xAxis = echartOptions.xAxis as {
+      axisLabel: { formatter: TimeFormatter };
+    };
+    return xAxis.axisLabel.formatter;
+  };
+
+  it('should work for days', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.DAY);
+    expect(formatter(1610000000000)).toEqual(
+      expect.stringMatching('2021-01-07'),
+    );
+  });
+
+  it('should work for weeks', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.WEEK);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(
+      expect.stringMatching('2021-01-07 — 2021-01-13'),
+    );
+  });
+
+  it('should work for months', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.MONTH);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('Jan'));
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+  });
+
+  it('should work for quarters', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.QUARTER);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('Q1'));
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+  });
+
+  it('should work for years', () => {
+    const formatter = getXAxisFormatter(TimeGranularity.QUARTER);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(expect.stringMatching('2021'));
+  });
+});
+
+describe('should add the correct time formatter for the tooltip', () => {
+  const getTooltipFormatter = (timeGrainSqla: TimeGranularity) => {
+    const updatedChartPropsConfig = {
+      ...chartPropsConfig,
+      formData: {
+        ...chartPropsConfig.formData,
+        time_grain_sqla: timeGrainSqla,
+        tooltipTimeFormat: '%Y-%m-%d',
+      },
+      queriesData: [
+        {
+          data: chartPropsConfig.queriesData[0].data,
+          label_map: chartPropsConfig.queriesData[0].label_map,
+          colnames: ['Boy', 'Girl', 'ds'],
+          coltypes: [
+            GenericDataType.String,
+            GenericDataType.String,
+            GenericDataType.Temporal,
+          ],
+        },
+        {
+          data: chartPropsConfig.queriesData[1].data,
+          label_map: chartPropsConfig.queriesData[1].label_map,
+          colnames: ['Boy', 'Girl', 'ds'],
+          coltypes: [
+            GenericDataType.String,
+            GenericDataType.String,
+            GenericDataType.Temporal,
+          ],
+        },
+      ],
+    };
+
+    return transformProps(
+      new ChartProps(updatedChartPropsConfig) as EchartsMixedTimeseriesProps,
+    ).xValueFormatter;
+  };
+
+  it('should work for days', () => {
+    const formatter = getTooltipFormatter(TimeGranularity.DAY);
+    expect(formatter(1610000000000)).toEqual(
+      expect.stringMatching('2021-01-07'),
+    );
+  });
+
+  it('should work for weeks', () => {
+    const formatter = getTooltipFormatter(TimeGranularity.WEEK);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(
+      expect.stringMatching('2021-01-07 — 2021-01-13'),
+    );
+  });
+
+  it('should work for months', () => {
+    const formatter = getTooltipFormatter(TimeGranularity.MONTH);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('Jan'));
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+  });
+
+  it('should work for quarters', () => {
+    const formatter = getTooltipFormatter(TimeGranularity.QUARTER);
+    expect(formatter).toBeDefined();
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('Q1'));
+    expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+  });
+
+  it('should work for years', () => {
+    const formatter = getTooltipFormatter(TimeGranularity.QUARTER);

Review Comment:
   In the 'should work for years' tooltip test, you’re passing 
TimeGranularity.QUARTER instead of TimeGranularity.YEAR.
   ```suggestion
       const formatter = getTooltipFormatter(TimeGranularity.YEAR);
   ```



##########
superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts:
##########
@@ -633,4 +636,133 @@ describe('Does transformProps transform series 
correctly', () => {
       'foo2, bar2': ['foo2', 'bar2'],
     });
   });
+
+  describe('should add the correct time formatter for the xAxis', () => {
+    const getXAxisFormatter = (timeGrainSqla: TimeGranularity) => {
+      const updatedChartPropsConfig = {
+        ...chartPropsConfig,
+        formData: {
+          ...chartPropsConfig.formData,
+          time_grain_sqla: timeGrainSqla,
+          xAxisTimeFormat: '%Y-%m-%d',
+        },
+        queriesData: [
+          {
+            data: chartPropsConfig.queriesData[0].data,
+            colnames: ['San Francisco', 'New York', '__timestamp'],
+            coltypes: [
+              GenericDataType.String,
+              GenericDataType.String,
+              GenericDataType.Temporal,
+            ],
+          },
+        ],
+      };
+      const { echartOptions } = transformProps(
+        new ChartProps(updatedChartPropsConfig) as EchartsTimeseriesChartProps,
+      );
+      const xAxis = echartOptions.xAxis as {
+        axisLabel: { formatter: TimeFormatter };
+      };
+      return xAxis.axisLabel.formatter;
+    };
+
+    it('should work for days', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.DAY);
+      expect(formatter(1610000000000)).toEqual(
+        expect.stringMatching('2021-01-07'),
+      );
+    });
+
+    it('should work for weeks', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.WEEK);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(
+        expect.stringMatching('2021-01-07 — 2021-01-13'),
+      );
+    });
+
+    it('should work for months', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.MONTH);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(expect.stringContaining('Jan'));
+      
expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+    });
+
+    it('should work for quarters', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.QUARTER);
+      expect(formatter).toBeDefined();
+      expect(formatter(1610000000000)).toEqual(expect.stringContaining('Q1'));
+      
expect(formatter(1610000000000)).toEqual(expect.stringContaining('2021'));
+    });
+
+    it('should work for years', () => {
+      const formatter = getXAxisFormatter(TimeGranularity.QUARTER);

Review Comment:
   In the 'should work for years' xAxis test, you’re passing 
TimeGranularity.QUARTER. It should be TimeGranularity.YEAR to verify the year 
formatter.
   ```suggestion
         const formatter = getXAxisFormatter(TimeGranularity.YEAR);
   ```



-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to