From 9c7bcfceadb1101899d6c09330aa8e79330d656f Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Wed, 20 Jul 2022 19:56:03 +0800 Subject: [PATCH] fix: core coverage and add a coverage step in workflow (#20784) * fix: core coverage * add step in workflow --- .github/workflows/superset-frontend.yml | 5 +++ .../src/query/types/Datasource.ts | 3 -- .../test/query/DatasourceKey.test.ts | 12 ++++-- .../test/query/types/Datasource.test.ts | 37 +++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 superset-frontend/packages/superset-ui-core/test/query/types/Datasource.test.ts diff --git a/.github/workflows/superset-frontend.yml b/.github/workflows/superset-frontend.yml index 03e2b9e7d4207..bf09d293c6e3a 100644 --- a/.github/workflows/superset-frontend.yml +++ b/.github/workflows/superset-frontend.yml @@ -51,6 +51,11 @@ jobs: if: steps.check.outcome == 'failure' working-directory: ./superset-frontend run: npm run plugins:build-storybook + - name: superset-ui/core coverage + if: steps.check.outcome == 'failure' + working-directory: ./superset-frontend + run: | + npm run core:cover - name: unit tests if: steps.check.outcome == 'failure' working-directory: ./superset-frontend diff --git a/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts b/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts index e53a8d05ff653..9639a000d0151 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts @@ -53,7 +53,4 @@ export const DEFAULT_METRICS: Metric[] = [ }, ]; -export const isValidDatasourceType = (datasource: DatasourceType) => - Object.values(DatasourceType).includes(datasource); - export default {}; diff --git a/superset-frontend/packages/superset-ui-core/test/query/DatasourceKey.test.ts b/superset-frontend/packages/superset-ui-core/test/query/DatasourceKey.test.ts index d7629bc1b1ca5..4a3c8772c372d 100644 --- a/superset-frontend/packages/superset-ui-core/test/query/DatasourceKey.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/query/DatasourceKey.test.ts @@ -19,11 +19,15 @@ import { DatasourceKey } from '@superset-ui/core'; describe('DatasourceKey', () => { - const tableKey = '5__table'; - it('should handle table data sources', () => { - const datasourceKey = new DatasourceKey(tableKey); - expect(datasourceKey.toString()).toBe(tableKey); + const datasourceKey = new DatasourceKey('5__table'); + expect(datasourceKey.toString()).toBe('5__table'); expect(datasourceKey.toObject()).toEqual({ id: 5, type: 'table' }); }); + + it('should handle query data sources', () => { + const datasourceKey = new DatasourceKey('5__query'); + expect(datasourceKey.toString()).toBe('5__query'); + expect(datasourceKey.toObject()).toEqual({ id: 5, type: 'query' }); + }); }); diff --git a/superset-frontend/packages/superset-ui-core/test/query/types/Datasource.test.ts b/superset-frontend/packages/superset-ui-core/test/query/types/Datasource.test.ts new file mode 100644 index 0000000000000..c80f3d6950017 --- /dev/null +++ b/superset-frontend/packages/superset-ui-core/test/query/types/Datasource.test.ts @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { DatasourceType, DEFAULT_METRICS } from '@superset-ui/core'; + +test('DEFAULT_METRICS', () => { + expect(DEFAULT_METRICS).toEqual([ + { + metric_name: 'COUNT(*)', + expression: 'COUNT(*)', + }, + ]); +}); + +test('DatasourceType', () => { + expect(Object.keys(DatasourceType).length).toBe(5); + expect(DatasourceType.Table).toBe('table'); + expect(DatasourceType.Query).toBe('query'); + expect(DatasourceType.Dataset).toBe('dataset'); + expect(DatasourceType.SlTable).toBe('sl_table'); + expect(DatasourceType.SavedQuery).toBe('saved_query'); +});