diff --git a/packages/superset-ui-core/test/query/extractQueryFields.test.ts b/packages/superset-ui-core/test/query/extractQueryFields.test.ts index b0d410400d..2960efef4a 100644 --- a/packages/superset-ui-core/test/query/extractQueryFields.test.ts +++ b/packages/superset-ui-core/test/query/extractQueryFields.test.ts @@ -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', () => { @@ -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'], + }); + }); }); diff --git a/packages/superset-ui-core/test/time-format/factories/createD3TimeFormatter.test.ts b/packages/superset-ui-core/test/time-format/factories/createD3TimeFormatter.test.ts index 33eb65cefa..f918c1f08b 100644 --- a/packages/superset-ui-core/test/time-format/factories/createD3TimeFormatter.test.ts +++ b/packages/superset-ui-core/test/time-format/factories/createD3TimeFormatter.test.ts @@ -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); }); }); @@ -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); }); }); }); diff --git a/packages/superset-ui-core/test/utils/removeDuplicates.test.ts b/packages/superset-ui-core/test/utils/removeDuplicates.test.ts new file mode 100644 index 0000000000..3ba21dcfc8 --- /dev/null +++ b/packages/superset-ui-core/test/utils/removeDuplicates.test.ts @@ -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 }, + ]); + }); +});