chore: add type checking in plugin test directory (#19387)

This commit is contained in:
Stephen Liu
2022-03-28 10:20:06 +08:00
committed by GitHub
parent 5ae7e54999
commit 6f5778273e
21 changed files with 91 additions and 56 deletions

View File

@@ -57,7 +57,7 @@ const rawFormData = {
function generateProps(
data: BigNumberDatum[],
extraFormData = {},
extraQueryData = {},
extraQueryData: any = {},
): BigNumberWithTrendlineChartProps {
return {
width: 200,

View File

@@ -16,12 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
import { isPostProcessingBoxplot } from '@superset-ui/core';
import {
isPostProcessingBoxplot,
PostProcessingBoxplot,
} from '@superset-ui/core';
import { DEFAULT_TITLE_FORM_DATA } from '../../src/types';
import buildQuery from '../../src/BoxPlot/buildQuery';
import { BoxPlotQueryFormData } from '../../src/BoxPlot/types';
describe('BoxPlot buildQuery', () => {
const formData: BoxPlotQueryFormData = {
...DEFAULT_TITLE_FORM_DATA,
emitFilter: false,
columns: [],
datasource: '5__table',
@@ -42,7 +47,7 @@ describe('BoxPlot buildQuery', () => {
expect(query.series_columns).toEqual(['bar']);
const [rule] = query.post_processing || [];
expect(isPostProcessingBoxplot(rule)).toEqual(true);
expect(rule.options.groupby).toEqual(['bar']);
expect((rule as PostProcessingBoxplot)?.options?.groupby).toEqual(['bar']);
});
it('should build non-timeseries query object when columns is defined', () => {
@@ -53,6 +58,6 @@ describe('BoxPlot buildQuery', () => {
expect(query.series_columns).toEqual(['bar']);
const [rule] = query.post_processing || [];
expect(isPostProcessingBoxplot(rule)).toEqual(true);
expect(rule.options.groupby).toEqual(['bar']);
expect((rule as PostProcessingBoxplot)?.options?.groupby).toEqual(['bar']);
});
});

View File

@@ -16,11 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
import { ChartProps } from '@superset-ui/core';
import { ChartProps, SqlaFormData } from '@superset-ui/core';
import { EchartsBoxPlotChartProps } from '../../src/BoxPlot/types';
import transformProps from '../../src/BoxPlot/transformProps';
describe('BoxPlot tranformProps', () => {
const formData = {
const formData: SqlaFormData = {
datasource: '5__table',
granularity_sqla: 'ds',
time_grain_sqla: 'P1Y',
@@ -68,7 +69,7 @@ describe('BoxPlot tranformProps', () => {
});
it('should tranform chart props for viz', () => {
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsBoxPlotChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,

View File

@@ -20,7 +20,10 @@ import { ChartProps, getNumberFormatter } from '@superset-ui/core';
import transformProps, {
formatFunnelLabel,
} from '../../src/Funnel/transformProps';
import { EchartsFunnelLabelTypeType } from '../../src/Funnel/types';
import {
EchartsFunnelChartProps,
EchartsFunnelLabelTypeType,
} from '../../src/Funnel/types';
describe('Funnel tranformProps', () => {
const formData = {
@@ -45,7 +48,7 @@ describe('Funnel tranformProps', () => {
});
it('should tranform chart props for viz', () => {
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsFunnelChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,

View File

@@ -26,7 +26,7 @@ describe('Gauge buildQuery', () => {
};
it('should build query fields with no group by column', () => {
const formData = { ...baseFormData, groupby: null };
const formData = { ...baseFormData, groupby: undefined };
const queryContext = buildQuery(formData);
const [query] = queryContext.queries;
expect(query.groupby).toEqual([]);

View File

@@ -16,18 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
import { ChartProps } from '@superset-ui/core';
import { ChartProps, SqlaFormData } from '@superset-ui/core';
import transformProps from '../../src/Gauge/transformProps';
import { DEFAULT_GAUGE_SERIES_OPTION } from '../../src/Gauge/constants';
import { EchartsGaugeChartProps } from '../../src/Gauge/types';
describe('Echarts Gauge transformProps', () => {
const baseFormData = {
const baseFormData: SqlaFormData = {
datasource: '26__table',
vizType: 'gauge_chart',
viz_type: 'gauge_chart',
metric: 'count',
adhocFilters: [],
rowLimit: 10,
minVal: '0',
minVal: 0,
maxVal: 100,
startAngle: 225,
endAngle: -45,
@@ -46,7 +46,7 @@ describe('Echarts Gauge transformProps', () => {
};
it('should transform chart props for no group by column', () => {
const formData = { ...baseFormData, groupby: [] };
const formData: SqlaFormData = { ...baseFormData, groupby: [] };
const queriesData = [
{
colnames: ['count'],
@@ -66,7 +66,7 @@ describe('Echarts Gauge transformProps', () => {
};
const chartProps = new ChartProps(chartPropsConfig);
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsGaugeChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,
@@ -98,7 +98,10 @@ describe('Echarts Gauge transformProps', () => {
});
it('should transform chart props for single group by column', () => {
const formData = { ...baseFormData, groupby: ['year'] };
const formData: SqlaFormData = {
...baseFormData,
groupby: ['year'],
};
const queriesData = [
{
colnames: ['year', 'count'],
@@ -123,7 +126,7 @@ describe('Echarts Gauge transformProps', () => {
};
const chartProps = new ChartProps(chartPropsConfig);
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsGaugeChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,
@@ -170,7 +173,10 @@ describe('Echarts Gauge transformProps', () => {
});
it('should transform chart props for multiple group by columns', () => {
const formData = { ...baseFormData, groupby: ['year', 'platform'] };
const formData: SqlaFormData = {
...baseFormData,
groupby: ['year', 'platform'],
};
const queriesData = [
{
colnames: ['year', 'platform', 'count'],
@@ -197,7 +203,7 @@ describe('Echarts Gauge transformProps', () => {
};
const chartProps = new ChartProps(chartPropsConfig);
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsGaugeChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,
@@ -244,7 +250,7 @@ describe('Echarts Gauge transformProps', () => {
});
it('should transform chart props for intervals', () => {
const formData = {
const formData: SqlaFormData = {
...baseFormData,
groupby: ['year', 'platform'],
intervals: '50,100',
@@ -276,7 +282,7 @@ describe('Echarts Gauge transformProps', () => {
};
const chartProps = new ChartProps(chartPropsConfig);
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsGaugeChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,

View File

@@ -22,7 +22,7 @@ import {
SqlaFormData,
} from '@superset-ui/core';
import transformProps, { formatPieLabel } from '../../src/Pie/transformProps';
import { EchartsPieLabelType } from '../../src/Pie/types';
import { EchartsPieChartProps, EchartsPieLabelType } from '../../src/Pie/types';
describe('Pie tranformProps', () => {
const formData: SqlaFormData = {
@@ -48,7 +48,7 @@ describe('Pie tranformProps', () => {
});
it('should tranform chart props for viz', () => {
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsPieChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,

View File

@@ -24,12 +24,14 @@ import {
EventAnnotationLayer,
FormulaAnnotationLayer,
IntervalAnnotationLayer,
SqlaFormData,
TimeseriesAnnotationLayer,
} from '@superset-ui/core';
import { EchartsTimeseriesChartProps } from '../../src/types';
import transformProps from '../../src/Timeseries/transformProps';
describe('EchartsTimeseries transformProps', () => {
const formData = {
const formData: SqlaFormData = {
colorScheme: 'bnbColors',
datasource: '3__table',
granularity_sqla: 'ds',
@@ -54,7 +56,7 @@ describe('EchartsTimeseries transformProps', () => {
it('should tranform chart props for viz', () => {
const chartProps = new ChartProps(chartPropsConfig);
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsTimeseriesChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,
@@ -99,7 +101,7 @@ describe('EchartsTimeseries transformProps', () => {
annotationLayers: [formula],
},
});
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsTimeseriesChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,
@@ -227,7 +229,7 @@ describe('EchartsTimeseries transformProps', () => {
},
],
});
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsTimeseriesChartProps)).toEqual(
expect.objectContaining({
echartOptions: expect.objectContaining({
legend: expect.objectContaining({
@@ -266,7 +268,8 @@ describe('Does transformProps transform series correctly', () => {
name: string;
};
const formData = {
const formData: SqlaFormData = {
viz_type: 'my_viz',
colorScheme: 'bnbColors',
datasource: '3__table',
granularity_sqla: 'ds',
@@ -329,8 +332,9 @@ describe('Does transformProps transform series correctly', () => {
it('should show labels when showValue is true', () => {
const chartProps = new ChartProps(chartPropsConfig);
const transformedSeries = transformProps(chartProps).echartOptions
.series as seriesType[];
const transformedSeries = transformProps(
chartProps as EchartsTimeseriesChartProps,
).echartOptions.series as seriesType[];
transformedSeries.forEach(series => {
expect(series.label.show).toBe(true);
@@ -345,8 +349,9 @@ describe('Does transformProps transform series correctly', () => {
const chartProps = new ChartProps(updatedChartPropsConfig);
const transformedSeries = transformProps(chartProps).echartOptions
.series as seriesType[];
const transformedSeries = transformProps(
chartProps as EchartsTimeseriesChartProps,
).echartOptions.series as seriesType[];
transformedSeries.forEach(series => {
expect(series.label.show).toBe(false);
@@ -361,8 +366,9 @@ describe('Does transformProps transform series correctly', () => {
const chartProps = new ChartProps(updatedChartPropsConfig);
const transformedSeries = transformProps(chartProps).echartOptions
.series as seriesType[];
const transformedSeries = transformProps(
chartProps as EchartsTimeseriesChartProps,
).echartOptions.series as seriesType[];
const showValueIndexes: number[] = [];
@@ -400,8 +406,9 @@ describe('Does transformProps transform series correctly', () => {
it('should show labels on values >= percentageThreshold if onlyTotal is false', () => {
const chartProps = new ChartProps(chartPropsConfig);
const transformedSeries = transformProps(chartProps).echartOptions
.series as seriesType[];
const transformedSeries = transformProps(
chartProps as EchartsTimeseriesChartProps,
).echartOptions.series as seriesType[];
const expectedThresholds = totalStackedValues.map(
total => ((formData.percentageThreshold || 0) / 100) * total,
@@ -430,8 +437,9 @@ describe('Does transformProps transform series correctly', () => {
const chartProps = new ChartProps(updatedChartPropsConfig);
const transformedSeries = transformProps(chartProps).echartOptions
.series as seriesType[];
const transformedSeries = transformProps(
chartProps as EchartsTimeseriesChartProps,
).echartOptions.series as seriesType[];
transformedSeries.forEach((series, seriesIndex) => {
expect(series.label.show).toBe(true);

View File

@@ -17,6 +17,7 @@
* under the License.
*/
import { ChartProps } from '@superset-ui/core';
import { EchartsTreemapChartProps } from '../../src/Treemap/types';
import transformProps from '../../src/Treemap/transformProps';
describe('Treemap tranformProps', () => {
@@ -42,7 +43,7 @@ describe('Treemap tranformProps', () => {
});
it('should tranform chart props for viz', () => {
expect(transformProps(chartProps)).toEqual(
expect(transformProps(chartProps as EchartsTreemapChartProps)).toEqual(
expect.objectContaining({
width: 800,
height: 600,