Skip to content

Commit

Permalink
chore: add type checking in plugin test directory (#19387)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenLYZ committed Mar 28, 2022
1 parent 5ae7e54 commit 6f57782
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ export type RecordAnnotationResult = {
records: DataRecord[];
};

export type TimeseriesAnnotationResult = [
{ key: string; values: { x: string | number; y?: number }[] },
];
export type TimeseriesAnnotationResult = {
key: string;
values: { x: string | number; y?: number }[];
}[];

export type AnnotationResult =
| RecordAnnotationResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export const DEFAULT_FORM_DATA: BoxPlotQueryFormData = {
...DEFAULT_TITLE_FORM_DATA,
};

export interface EchartsBoxPlotChartProps extends ChartProps {
export interface EchartsBoxPlotChartProps
extends ChartProps<BoxPlotQueryFormData> {
formData: BoxPlotQueryFormData;
queriesData: ChartDataResponseResult[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export enum EchartsFunnelLabelTypeType {
KeyValuePercent,
}

export interface EchartsFunnelChartProps extends ChartProps {
export interface EchartsFunnelChartProps
extends ChartProps<EchartsFunnelFormData> {
formData: EchartsFunnelFormData;
queriesData: ChartDataResponseResult[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type AxisTickLineStyle = {
export type EchartsGaugeFormData = QueryFormData & {
colorScheme?: string;
groupby: QueryFormColumn[];
metric?: object;
metric?: string;
rowLimit: number;
minVal: number;
maxVal: number;
Expand Down Expand Up @@ -78,7 +78,8 @@ export const DEFAULT_FORM_DATA: Partial<EchartsGaugeFormData> = {
emitFilter: false,
};

export interface EchartsGaugeChartProps extends ChartProps {
export interface EchartsGaugeChartProps
extends ChartProps<EchartsGaugeFormData> {
formData: EchartsGaugeFormData;
queriesData: ChartDataResponseResult[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export enum EchartsPieLabelType {
KeyValuePercent = 'key_value_percent',
}

export interface EchartsPieChartProps extends ChartProps {
export interface EchartsPieChartProps extends ChartProps<EchartsPieFormData> {
formData: EchartsPieFormData;
queriesData: ChartDataResponseResult[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export const DEFAULT_FORM_DATA: EchartsTimeseriesFormData = {
...DEFAULT_TITLE_FORM_DATA,
};

export interface EchartsTimeseriesChartProps extends ChartProps {
export interface EchartsTimeseriesChartProps
extends ChartProps<EchartsTimeseriesFormData> {
formData: EchartsTimeseriesFormData;
queriesData: ChartDataResponseResult[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export enum EchartsTreemapLabelType {
KeyValue = 'key_value',
}

export interface EchartsTreemapChartProps extends ChartProps {
export interface EchartsTreemapChartProps
extends ChartProps<EchartsTreemapFormData> {
formData: EchartsTreemapFormData;
queriesData: ChartDataResponseResult[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import { DataRecord, DTTM_ALIAS, NumberFormatter } from '@superset-ui/core';
import { CallbackDataParams, OptionName } from 'echarts/types/src/util/types';
import { OptionName } from 'echarts/types/src/util/types';
import { TooltipMarker } from 'echarts/types/src/util/format';
import {
ForecastSeriesContext,
Expand Down Expand Up @@ -52,7 +52,7 @@ export const extractForecastSeriesContexts = (
}, {} as { [key: string]: ForecastSeriesEnum[] });

export const extractForecastValuesFromTooltipParams = (
params: (CallbackDataParams & { seriesId: string })[],
params: any[],
): Record<string, ForecastValue> => {
const values: Record<string, ForecastValue> = {};
params.forEach(param => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const rawFormData = {
function generateProps(
data: BigNumberDatum[],
extraFormData = {},
extraQueryData = {},
extraQueryData: any = {},
): BigNumberWithTrendlineChartProps {
return {
width: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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', () => {
Expand All @@ -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']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'],
Expand All @@ -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,
Expand Down Expand Up @@ -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'],
Expand All @@ -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,
Expand Down Expand Up @@ -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'],
Expand All @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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,
Expand Down

0 comments on commit 6f57782

Please sign in to comment.