refactor: reorganize dateFilterUtils.tx (#14309)

* refactor: reorganize dateFilterUtils.tx

* move spec to src dirctory
This commit is contained in:
Yongjie Zhao
2021-04-23 16:05:50 +08:00
committed by GitHub
parent d1afca4fa1
commit 67535bb320
7 changed files with 45 additions and 47 deletions

View File

@@ -26,10 +26,6 @@ import {
shouldUseLegacyApi,
getSimpleSQLExpression,
} from 'src/explore/exploreUtils';
import {
buildTimeRangeString,
formatTimeRange,
} from 'src/explore/dateFilterUtils';
import { DashboardStandaloneMode } from 'src/dashboard/util/constants';
import * as hostNamesConfig from 'src/utils/hostNamesConfig';
import { getChartMetadataRegistry } from '@superset-ui/core';
@@ -264,40 +260,6 @@ describe('exploreUtils', () => {
});
});
describe('buildTimeRangeString', () => {
it('generates proper time range string', () => {
expect(
buildTimeRangeString('2010-07-30T00:00:00', '2020-07-30T00:00:00'),
).toBe('2010-07-30T00:00:00 : 2020-07-30T00:00:00');
expect(buildTimeRangeString('', '2020-07-30T00:00:00')).toBe(
' : 2020-07-30T00:00:00',
);
expect(buildTimeRangeString('', '')).toBe(' : ');
});
});
describe('formatTimeRange', () => {
it('generates a readable time range', () => {
expect(formatTimeRange('Last 7 days')).toBe('Last 7 days');
expect(formatTimeRange('No filter')).toBe('No filter');
expect(formatTimeRange('Yesterday : Tomorrow')).toBe(
'Yesterday < col < Tomorrow',
);
expect(
formatTimeRange('2010-07-30T00:00:00 : 2020-07-30T00:00:00', [
'inclusive',
'exclusive',
]),
).toBe('2010-07-30 ≤ col < 2020-07-30');
expect(
formatTimeRange('2010-07-30T01:00:00 : ', ['exclusive', 'inclusive']),
).toBe('2010-07-30T01:00:00 < col ≤ ∞');
expect(formatTimeRange(' : 2020-07-30T00:00:00')).toBe(
'-∞ < col < 2020-07-30',
);
});
});
describe('getSimpleSQLExpression', () => {
it('returns empty string when subject is undefined', () => {
expect(getSimpleSQLExpression(undefined, '=', 10)).toBe('');

View File

@@ -28,7 +28,11 @@ import {
import {
buildTimeRangeString,
formatTimeRange,
} from 'src/explore/dateFilterUtils';
COMMON_RANGE_VALUES_SET,
CALENDAR_RANGE_VALUES_SET,
FRAME_OPTIONS,
customTimeRangeDecode,
} from 'src/explore/components/controls/DateFilterControl/utils';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import Button from 'src/components/Button';
import ControlHeader from 'src/explore/components/ControlHeader';
@@ -43,12 +47,7 @@ import { useDebouncedEffect } from 'src/explore/exploreUtils';
import { SLOW_DEBOUNCE } from 'src/constants';
import { testWithId } from 'src/utils/testUtils';
import { SelectOptionType, FrameType } from './types';
import {
COMMON_RANGE_VALUES_SET,
CALENDAR_RANGE_VALUES_SET,
FRAME_OPTIONS,
customTimeRangeDecode,
} from './utils';
import {
CommonFrame,
CalendarFrame,

View File

@@ -18,7 +18,7 @@
*/
import React from 'react';
import { t } from '@superset-ui/core';
import { SEPARATOR } from 'src/explore/dateFilterUtils';
import { SEPARATOR } from 'src/explore/components/controls/DateFilterControl/utils';
import { Input } from 'src/common/components';
import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
import { FrameComponentProps } from 'src/explore/components/controls/DateFilterControl/types';

View File

@@ -17,13 +17,13 @@
* under the License.
*/
import moment, { Moment } from 'moment';
import { SEPARATOR } from 'src/explore/dateFilterUtils';
import {
CustomRangeDecodeType,
CustomRangeType,
DateTimeGrainType,
DateTimeModeType,
} from 'src/explore/components/controls/DateFilterControl/types';
import { SEPARATOR } from './dateFilterUtils';
import { SEVEN_DAYS_AGO, MIDNIGHT, MOMENT_FORMAT } from './constants';
/**

View File

@@ -18,3 +18,4 @@
*/
export * from './dateParser';
export * from './constants';
export * from './dateFilterUtils';

View File

@@ -20,6 +20,8 @@
import {
customTimeRangeEncode,
customTimeRangeDecode,
buildTimeRangeString,
formatTimeRange,
} from 'src/explore/components/controls/DateFilterControl/utils';
describe('Custom TimeRange', () => {
@@ -296,3 +298,37 @@ describe('Custom TimeRange', () => {
});
});
});
describe('buildTimeRangeString', () => {
it('generates proper time range string', () => {
expect(
buildTimeRangeString('2010-07-30T00:00:00', '2020-07-30T00:00:00'),
).toBe('2010-07-30T00:00:00 : 2020-07-30T00:00:00');
expect(buildTimeRangeString('', '2020-07-30T00:00:00')).toBe(
' : 2020-07-30T00:00:00',
);
expect(buildTimeRangeString('', '')).toBe(' : ');
});
});
describe('formatTimeRange', () => {
it('generates a readable time range', () => {
expect(formatTimeRange('Last 7 days')).toBe('Last 7 days');
expect(formatTimeRange('No filter')).toBe('No filter');
expect(formatTimeRange('Yesterday : Tomorrow')).toBe(
'Yesterday < col < Tomorrow',
);
expect(
formatTimeRange('2010-07-30T00:00:00 : 2020-07-30T00:00:00', [
'inclusive',
'exclusive',
]),
).toBe('2010-07-30 ≤ col < 2020-07-30');
expect(
formatTimeRange('2010-07-30T01:00:00 : ', ['exclusive', 'inclusive']),
).toBe('2010-07-30T01:00:00 < col ≤ ∞');
expect(formatTimeRange(' : 2020-07-30T00:00:00')).toBe(
'-∞ < col < 2020-07-30',
);
});
});