Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Fix test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Jan 10, 2021
1 parent 53bfffb commit 7fb0819
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/superset-ui-core/test/query/extractQueryFields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import extractQueryFields from '@superset-ui/core/src/query/extractQueryFields';
import { QueryMode } from '../../src';
import { DTTM_ALIAS } from '../../src/query/buildQueryObject';

describe('extractQueryFields', () => {
Expand Down Expand Up @@ -84,4 +85,36 @@ describe('extractQueryFields', () => {
extractQueryFields({ groupby: ['col_1', DTTM_ALIAS, ''], include_time: true }).columns,
).toEqual(['col_1', DTTM_ALIAS]);
});

it('should ignore null values', () => {
expect(extractQueryFields({ series: ['a'], columns: null }).columns).toEqual(['a']);
});

it('should ignore groupby when in raw QueryMode', () => {
expect(
extractQueryFields({
columns: ['a'],
groupby: ['b'],
metric: ['m'],
query_mode: QueryMode.raw,
}),
).toEqual({
metrics: ['m'],
columns: ['a'],
});
});

it('should ignore columns when in aggregate QueryMode', () => {
expect(
extractQueryFields({
columns: ['a'],
groupby: ['b'],
metric: ['m'],
query_mode: QueryMode.aggregate,
}),
).toEqual({
metrics: ['m'],
columns: ['b'],
});
});
});
31 changes: 31 additions & 0 deletions packages/superset-ui-core/test/utils/removeDuplicates.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* 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 { removeDuplicates } from '@superset-ui/core/src';

describe('removeDuplicates([...])', () => {
it('should remove duplciages from a simple list', () => {
expect(removeDuplicates([1, 2, 4, 1, 1, 5, 2])).toEqual([1, 2, 4, 5]);
});
it('should remove duplciages by key getter', () => {
expect(removeDuplicates([{ a: 1 }, { a: 1 }, { b: 2 }], x => x.a)).toEqual([
{ a: 1 },
{ b: 2 },
]);
});
});

0 comments on commit 7fb0819

Please sign in to comment.