From 3ac5dabfa6c812202d293dbaa517cac0cb0744a7 Mon Sep 17 00:00:00 2001 From: Jesse Yang Date: Mon, 8 Mar 2021 09:59:19 -0800 Subject: [PATCH] Add test --- plugins/plugin-chart-table/src/buildQuery.ts | 4 ++-- plugins/plugin-chart-table/src/index.ts | 6 ++--- .../test/buildQuery.test.ts | 22 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/plugins/plugin-chart-table/src/buildQuery.ts b/plugins/plugin-chart-table/src/buildQuery.ts index c96b4b5d37..cd8e399e3d 100644 --- a/plugins/plugin-chart-table/src/buildQuery.ts +++ b/plugins/plugin-chart-table/src/buildQuery.ts @@ -126,7 +126,7 @@ const buildQuery: BuildQuery = (formData: TableChartFormData // Use this closure to cache changing of external filters, if we have server pagination we need reset page to 0, after // external filter changed -const cachedBuildQuery = (): BuildQuery => { +export const cachedBuildQuery = (): BuildQuery => { let cachedChanges: any = {}; const setCachedChanges = (newChanges: any) => { cachedChanges = { ...cachedChanges, ...newChanges }; @@ -146,4 +146,4 @@ const cachedBuildQuery = (): BuildQuery => { ); }; -export default cachedBuildQuery; +export default cachedBuildQuery(); diff --git a/plugins/plugin-chart-table/src/index.ts b/plugins/plugin-chart-table/src/index.ts index 898717e477..ff47298054 100644 --- a/plugins/plugin-chart-table/src/index.ts +++ b/plugins/plugin-chart-table/src/index.ts @@ -16,11 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -import { t, ChartMetadata, ChartPlugin, BuildQueryFunction } from '@superset-ui/core'; +import { t, ChartMetadata, ChartPlugin } from '@superset-ui/core'; import transformProps from './transformProps'; import thumbnail from './images/thumbnail.png'; import controlPanel from './controlPanel'; -import cachedBuildQuery from './buildQuery'; +import buildQuery from './buildQuery'; import { TableChartFormData, TableChartProps } from './types'; // must export something for the module to be exist in dev mode @@ -41,7 +41,7 @@ export default class TableChartPlugin extends ChartPlugin, + buildQuery, }); } } diff --git a/plugins/plugin-chart-table/test/buildQuery.test.ts b/plugins/plugin-chart-table/test/buildQuery.test.ts index 015cc0a9e5..18e3758635 100644 --- a/plugins/plugin-chart-table/test/buildQuery.test.ts +++ b/plugins/plugin-chart-table/test/buildQuery.test.ts @@ -17,7 +17,7 @@ * under the License. */ import { QueryMode } from '@superset-ui/core'; -import buildQueryCached from '../src/buildQuery'; +import buildQuery from '../src/buildQuery'; import { TableChartFormData } from '../src/types'; const basicFormData: TableChartFormData = { @@ -27,27 +27,27 @@ const basicFormData: TableChartFormData = { describe('plugin-chart-table', () => { describe('buildQuery', () => { - it('should add post-processing in aggregate mode', () => { - const query = buildQueryCached()({ + it('should add post-processing and ignore duplicate metrics', () => { + const query = buildQuery({ ...basicFormData, query_mode: QueryMode.aggregate, - metrics: ['aaa'], - percent_metrics: ['pct_abc'], + metrics: ['aaa', 'aaa'], + percent_metrics: ['bbb', 'bbb'], }).queries[0]; - expect(query.metrics).toEqual(['aaa', 'pct_abc']); + expect(query.metrics).toEqual(['aaa', 'bbb']); expect(query.post_processing).toEqual([ { operation: 'contribution', options: { - columns: ['pct_abc'], - rename_columns: ['%pct_abc'], + columns: ['bbb'], + rename_columns: ['%bbb'], }, }, ]); }); - it('should not add post-processing when there is not percent metric', () => { - const query = buildQueryCached()({ + it('should not add post-processing when there is no percent metric', () => { + const query = buildQuery({ ...basicFormData, query_mode: QueryMode.aggregate, metrics: ['aaa'], @@ -58,7 +58,7 @@ describe('plugin-chart-table', () => { }); it('should not add post-processing in raw records mode', () => { - const query = buildQueryCached()({ + const query = buildQuery({ ...basicFormData, query_mode: QueryMode.raw, metrics: ['aaa'],