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 6f10263
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 13 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'],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ describe('createD3TimeFormatter(config)', () => {
formatString: TimeFormats.DATABASE_DATETIME,
useLocalTime: true,
});
const offset = new Date().getTimezoneOffset();
// eslint-disable-next-line jest/no-if
if (offset === 0) {
expect(formatter.format(PREVIEW_TIME)).toEqual('2017-02-14 11:22:33');
} else {
expect(formatter.format(PREVIEW_TIME)).not.toEqual('2017-02-14 11:22:33');
}
const formatterInUTC = createD3TimeFormatter({
formatString: TimeFormats.DATABASE_DATETIME,
});
const offset = new Date().getTimezoneOffset(); // in minutes
const expected =
offset === 0
? '2017-02-14 11:22:33'
: formatterInUTC(new Date(PREVIEW_TIME.valueOf() - 60 * 1000 * offset));
expect(formatter.format(PREVIEW_TIME)).toEqual(expected);
});
});

Expand All @@ -84,13 +86,16 @@ describe('createD3TimeFormatter(config)', () => {
locale: thLocale,
useLocalTime: true,
});
const formatterInUTC = createD3TimeFormatter({
formatString: '%c',
locale: thLocale,
});
const offset = new Date().getTimezoneOffset();
// eslint-disable-next-line jest/no-if
if (offset === 0) {
expect(formatter(TEST_TIME)).toEqual('อา. 20 ธ.ค. 2015 00:00:00');
} else {
expect(formatter(TEST_TIME)).not.toEqual('อา. 20 ธ.ค. 2015 00:00:00');
}
const expected =
offset === 0
? 'อา. 20 ธ.ค. 2015 00:00:00'
: formatterInUTC(new Date(TEST_TIME.valueOf() - 60 * 1000 * offset));
expect(formatter(TEST_TIME)).toEqual(expected);
});
});
});
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 6f10263

Please sign in to comment.