mirror of
https://github.com/apache/superset.git
synced 2026-04-07 10:31:50 +00:00
refactor: reorganize dateFilterUtils.tx (#14309)
* refactor: reorganize dateFilterUtils.tx * move spec to src dirctory
This commit is contained in:
@@ -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('');
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,3 +18,4 @@
|
||||
*/
|
||||
export * from './dateParser';
|
||||
export * from './constants';
|
||||
export * from './dateFilterUtils';
|
||||
|
||||
@@ -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',
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user