Skip to content

Commit

Permalink
added tests for all plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
aadhikari committed Jun 26, 2023
1 parent 13f908c commit 6a811c5
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t, ChartMetadata, Behavior } from '@superset-ui/core';
import { t, Behavior } from '@superset-ui/core';
import controlPanel from './controlPanel';
import transformProps from './transformProps';
import buildQuery from './buildQuery';
Expand All @@ -26,7 +26,7 @@ import thumbnail from './images/thumbnail.png';
import { BigNumberTotalChartProps, BigNumberTotalFormData } from '../types';
import { EchartsChartPlugin } from '../../types';

const metadata = new ChartMetadata({
const metadata = {
category: t('KPI'),
description: t(
'Showcases a single metric front-and-center. Big number is best used to call attention to a KPI or the one thing you want your audience to focus on.',
Expand All @@ -47,7 +47,7 @@ const metadata = new ChartMetadata({
],
thumbnail,
behaviors: [Behavior.DRILL_TO_DETAIL],
});
};

export default class BigNumberTotalChartPlugin extends EchartsChartPlugin<
BigNumberTotalFormData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t, ChartMetadata, Behavior } from '@superset-ui/core';
import { t, Behavior } from '@superset-ui/core';
import controlPanel from './controlPanel';
import transformProps from './transformProps';
import buildQuery from './buildQuery';
Expand All @@ -28,7 +28,7 @@ import {
} from '../types';
import { EchartsChartPlugin } from '../../types';

const metadata = new ChartMetadata({
const metadata = {
category: t('KPI'),
description: t(
'Showcases a single number accompanied by a simple line chart, to call attention to an important metric along with its change over time or other dimension.',
Expand All @@ -46,7 +46,7 @@ const metadata = new ChartMetadata({
],
thumbnail,
behaviors: [Behavior.DRILL_TO_DETAIL],
});
};

export default class BigNumberWithTrendlineChartPlugin extends EchartsChartPlugin<
BigNumberWithTrendlineFormData,
Expand Down
9 changes: 4 additions & 5 deletions superset-frontend/plugins/plugin-chart-echarts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,14 @@ export class EchartsChartPlugin<
P extends ChartProps = ChartProps,
> extends ChartPlugin<T, P> {
constructor(props: any) {
const { metadata } = props;
const mergedProps = {
...props,
const { metadata, ...restProps } = props;
super({
...restProps,
metadata: new ChartMetadata({
parseMethod: 'json',
...metadata,
}),
};
super(mergedProps);
});
}
}

Expand Down

This file was deleted.

108 changes: 100 additions & 8 deletions superset-frontend/plugins/plugin-chart-echarts/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,107 @@ import {
EchartsGraphChartPlugin,
EchartsFunnelChartPlugin,
EchartsTreemapChartPlugin,
EchartsAreaChartPlugin,
EchartsTimeseriesBarChartPlugin,
EchartsTimeseriesLineChartPlugin,
EchartsTimeseriesScatterChartPlugin,
EchartsTimeseriesSmoothLineChartPlugin,
EchartsTimeseriesStepChartPlugin,
EchartsMixedTimeseriesChartPlugin,
EchartsGaugeChartPlugin,
EchartsRadarChartPlugin,
EchartsTreeChartPlugin,
BigNumberChartPlugin,
BigNumberTotalChartPlugin,
EchartsSunburstChartPlugin,
} from '../src';

describe('@superset-ui/plugin-chart-echarts', () => {
it('exists', () => {
expect(EchartsBoxPlotChartPlugin).toBeDefined();
expect(EchartsPieChartPlugin).toBeDefined();
expect(EchartsTimeseriesChartPlugin).toBeDefined();
expect(EchartsGraphChartPlugin).toBeDefined();
expect(EchartsFunnelChartPlugin).toBeDefined();
expect(EchartsTreemapChartPlugin).toBeDefined();
import { EchartsChartPlugin } from '../src/types';

test('@superset-ui/plugin-chart-echarts exists', () => {
expect(EchartsBoxPlotChartPlugin).toBeDefined();
expect(EchartsPieChartPlugin).toBeDefined();
expect(EchartsTimeseriesChartPlugin).toBeDefined();
expect(EchartsGraphChartPlugin).toBeDefined();
expect(EchartsFunnelChartPlugin).toBeDefined();
expect(EchartsTreemapChartPlugin).toBeDefined();
expect(EchartsAreaChartPlugin).toBeDefined();
expect(EchartsTimeseriesBarChartPlugin).toBeDefined();
expect(EchartsTimeseriesLineChartPlugin).toBeDefined();
expect(EchartsTimeseriesScatterChartPlugin).toBeDefined();
expect(EchartsTimeseriesSmoothLineChartPlugin).toBeDefined();
expect(EchartsTimeseriesStepChartPlugin).toBeDefined();
expect(EchartsMixedTimeseriesChartPlugin).toBeDefined();
expect(EchartsGaugeChartPlugin).toBeDefined();
expect(EchartsRadarChartPlugin).toBeDefined();
expect(EchartsTreeChartPlugin).toBeDefined();
expect(BigNumberChartPlugin).toBeDefined();
expect(BigNumberTotalChartPlugin).toBeDefined();
expect(EchartsSunburstChartPlugin).toBeDefined();
});

test('@superset-ui/plugin-chart-echarts-parsemethod-validation', () => {
const plugins: EchartsChartPlugin[] = [
new EchartsBoxPlotChartPlugin().configure({
key: 'box_plot',
}),
new EchartsPieChartPlugin().configure({
key: 'pie',
}),
new EchartsTimeseriesChartPlugin().configure({
key: 'echarts_timeseries',
}),
new EchartsGraphChartPlugin().configure({
key: 'graph_chart',
}),
new EchartsFunnelChartPlugin().configure({
key: 'funnel',
}),
new EchartsTreemapChartPlugin().configure({
key: 'treemap_v2',
}),
new EchartsAreaChartPlugin().configure({
key: 'echarts_area',
}),
new EchartsTimeseriesBarChartPlugin().configure({
key: 'echarts_timeseries_bar',
}),
new EchartsTimeseriesLineChartPlugin().configure({
key: 'echarts_timeseries_line',
}),
new EchartsTimeseriesScatterChartPlugin().configure({
key: 'echarts_timeseries_scatter',
}),
new EchartsTimeseriesSmoothLineChartPlugin().configure({
key: 'echarts_timeseries_smooth',
}),
new EchartsTimeseriesStepChartPlugin().configure({
key: 'echarts_timeseries_step',
}),
new EchartsMixedTimeseriesChartPlugin().configure({
key: 'mixed_timeseries',
}),
new EchartsGaugeChartPlugin().configure({
key: 'gauge_chart',
}),
new EchartsRadarChartPlugin().configure({
key: 'radar',
}),
new EchartsTreeChartPlugin().configure({
key: 'tree',
}),
new BigNumberChartPlugin().configure({
key: 'big_number',
}),
new BigNumberTotalChartPlugin().configure({
key: 'big_number_total',
}),
new EchartsSunburstChartPlugin().configure({
key: 'sunburst',
}),
];

plugins.forEach(plugin => {
expect(plugin.metadata.parseMethod).toEqual('json');
});
});

0 comments on commit 6a811c5

Please sign in to comment.